Hi,
I'm trying to create a utility method that will automatically create a
class for me, given a classname. But I can't find a way around having to
use eval().
This is what I'm doing right now:
def createClass(className)
eval(<<-EOS)
#{className} = Class.new do
#bla bla bla
end
EOS
end
but I really don't like eval() and would like to avoid it, if at all
possible.
Is there a reason, that Ruby doesn't support something like this: Maybe
because it's inconsistent with something, or because it's really hard?
className = "MyClass"
methodName = "myMethod"
class *className
def *methodName
puts "yay!"
end
end
Also, I find eval() code really messy. Though I'm not sure why. I think
I don't like it, because my editor (IntelliJ) doesn't do syntax
highlighting for strings. Do you guys know of any editors that will
syntax highlight a eval() string for you?
···
--
Posted via http://www.ruby-forum.com/.