From: DMisener Date: 2008-03-06T04:50:00+09:00 Subject: How to create a class in callers context?? Here's a simple example of my predicament: class Factory def self.generate name,_binding _name=name.to_s.capitalize eval %[ class #{_name} def to_s "#{_name}" end end ],_binding end end def Factory_generate what Factory.generate what,binding end Factory_generate :Thing puts Factory::Thing.new rescue puts "Can't Factory::Thing.new" # warning puts Thing .new rescue puts "Can't Thing.new" class Universe def initialize Factory_generate :Planet puts Universe::Planet.new rescue puts "Can't Universe::Planet.new" # warning puts Planet .new rescue puts "Can't Planet.new" end end Universe.new puts Universe::Planet.new rescue puts "Can't Universe::Planet.new" # warning puts Planet .new rescue puts "Can't Planet.new" --------------------------------------------- results in the following surprising output: C:/Work/class_eval.rb:20: warning: toplevel constant Thing referenced by Factory::Thing Thing Thing C:/Work/class_eval.rb:26: warning: toplevel constant Planet referenced by Universe::Planet Planet Planet C:/Work/class_eval.rb:33: warning: toplevel constant Planet referenced by Universe::Planet Planet Planet ---------------------------------------------- Questions: 1) What's the correct way to doing this? 2) I would have thought the non-qualified class references would have generated exceptions. 3) What is the warning message trying to convey.