# File lib/caesars.rb, line 510
510:   def self.inherited(modname)
511:     STDERR.puts "INHERITED: #{modname}" if Caesars.debug?
512:     
513:     # NOTE: We may be able to replace this without an eval using Module.nesting
514:     meth = (modname.to_s.split(/::/)).last.downcase  # Some::HighBall => highball
515:     
516:     # The method name "meth" is now a known symbol 
517:     # for the short class name (also "meth").
518:     Caesars.add_known_symbol(meth, meth)
519:     
520:     # We execute a module_eval form the namespace of the inherited class  
521:     # so when we define the new module DSL it will be Some::HighBall::DSL.
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