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.
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.
Here's my crack at this, not sure this is what you're trying to do:
def generate &name
eval("self",name.binding).class.class_eval <<-EOS
class #{name.call}
def to_s
name.call
end
end
EOS
end
class Universe
def initialize
generate{:Planet}
puts Universe::Planet
end
end
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.
Here's my crack at this, not sure this is what you're trying to do:
Had a small typo, here's the fixed example:
def generate &name
eval("self",name.binding).class.class_eval <<-EOS
class #{name.call}
def to_s
"#{name.call}"
end
end
EOS
end
class Universe
def initialize
generate{:Planet}
end
end