D
DMisener
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 lanet
puts Universe:lanet.new rescue puts "Can't
Universe:lanet.new" # warning
puts Planet .new rescue puts "Can't Planet.new"
end
end
Universe.new
puts Universe:lanet.new rescue puts "Can't
Universe:lanet.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:lanet
Planet
Planet
C:/Work/class_eval.rb:33: warning: toplevel constant Planet referenced
by Universe:lanet
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.
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 lanet
puts Universe:lanet.new rescue puts "Can't
Universe:lanet.new" # warning
puts Planet .new rescue puts "Can't Planet.new"
end
end
Universe.new
puts Universe:lanet.new rescue puts "Can't
Universe:lanet.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:lanet
Planet
Planet
C:/Work/class_eval.rb:33: warning: toplevel constant Planet referenced
by Universe:lanet
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.