ruby metaprogramming
DESCRIPTION
Ruby Metaprogramming. and other languages… . Metaprogramming. Writing programs that write programs (cool!) Often used to create domain-specific languages. Example*. class Module private def readonly (* syms ) # do nothing if no args return if syms.size == 0 - PowerPoint PPT PresentationTRANSCRIPT
Ruby
Ruby Metaprogrammingand other languages 1MetaprogrammingWriting programs that write programs (cool!)Often used to create domain-specific languages (DSL)
Youve all heard of at least one DSL written in Ruby. Can you guess what it is? Example*class Moduleprivate
def readonly(*syms) # do nothing if no args return if syms.size == 0 # code starts as empty string code = ""
# generate Ruby code to define # attr reader methods # Notice how the symbol is # interpolated into the code syms.each do |s| code