See the Class Notes link for more details about the programs. dslQA question and answer dsl define data structures, Quiz, etc. setup top-level methods, questions, right, and wrong to support the DSL. load DSL text -- fills data structures, a quiz full of questions run test eval instance_eval and class_eval Foo.class_eval {..} the Foo class Foo.instance_eval {..} the singleton class of Foo define_method defines an instance method in either case meta_intro metaprogramming introduction def o.say_hi defines singleton method of object o "all class methods are singleton methods of instances of Class" dsl2 list comprehension dsl From a Ruby point of view the main techniques use the instance_eval, eval, send, and the method_missing methods, and function closures. New instance variables are created dynamically in a local scope. The domain specific language allows instance_eval to change the context of evaluation while still providing access to the local scope. Each block is a closure that includes the bindings in effect. When a block is passed as an argument, its bindings is part of it and can be saved by the caller. Evaluating :self in the binding retrieves the self object that was bound to the block by the callee. The paper refers to the Variable Bindings in Ruby article. dsl gambling contracts First change DSL code to legal Ruby. Then execute it. The bubble method creates methods that just return their arguments. method_missing handles the game name. finally the result is converted to readable English. meta/cvs reading tables writes a class with the same name as a file, with getters and setters for each field of a record, and with an initialize method that sets each instance variable. The read method reads the file and for each record creates an instance of the class that was created. The end result is to map a file to Ruby objects. meta/attr1.rb showing how attr_reader could be defined defines my_attr_reader as a Module instance method. It uses class_eval to add a getter method definition for each symbol. It is called in a class definition where self is an instance of Class that inherits from Module. meta/contracts.rb adds software contract (see article) The user can define test methods and specify a contract for a method. When the method is defined, method_added is called which sets up the contract test. It writes a condition string of if statements, one to test each condition. It rewrites the user's method to evaluate the condition string and if no exception is raised to call the original method. finder/mf.rb,mf1.rb finds methods given action Uses the method and arity methods to find all methods that return a specified result when passed specified arguments. why/dwemthy.rb,eval.rb creatures fight dwemthy1.rb,eval1.rb simplified The class method, traits, gets executed when a class adds a trait attribute. It writes a getter and setter for each trait and a class method for each trait that adds the trait and its value to the @traits hash. It writes an initialize method sets an instance variable for each trait in the @traits hash to its value. When a Dragon class, say, is defined, the @traits hash gets four values added. When a Dragon instance, say, is defined the instance variables for each trait are set. The method_missing in DwemthysArray allows an array of creatures to fight by sending the method to the first creature in the array. routes/routelib.rb,routes.rb workflow -- hard way routes/routedsl.rb easyroute/rb workflow dsl Similar to the first Q&A dsl it defines the data, the Queue, Step, Route classes, etc. It defines the route, step, on, etc. methods for the DSL. routes/routedsl2.rb easyroute2.rb better workflow dsl functional programming functional programming in Ruby, map-reduce, Erlang