510: def self.inherited(modname)
511: STDERR.puts "INHERITED: #{modname}" if Caesars.debug?
512:
513:
514: meth = (modname.to_s.split(/::/)).last.downcase
515:
516:
517:
518: Caesars.add_known_symbol(meth, meth)
519:
520:
521:
522: modname.module_eval %Q{
523: module DSL
524: def #{meth}(*args, &b)
525: name = !args.empty? ? args.first.to_s : nil
526: varname = "@#{meth.to_s}"
527: varname << "_\#{name}" if name
528: inst = instance_variable_get(varname)
529:
530: # When the top level DSL method is called without a block
531: # it will return the appropriate instance variable name
532: return inst if b.nil?
533:
534: # Add to existing instance, if it exists. Otherwise create one anew.
535: # NOTE: Module.nesting[1] == modname (e.g. Some::HighBall)
536: inst = instance_variable_set(varname, inst || Module.nesting[1].new(name))
537: inst.instance_eval(&b)
538: inst
539: end
540:
541: def self.methname
542: :"#{meth}"
543: end
544:
545: end
546: }, __FILE__, __LINE__
547:
548: end