I have a ruby program, and I want to accept the user's made up method, and make a new method out of that name. I have tried this:
def method_missing(meth,*args,&block)
name = meth.to_s
class << self
define_method(name) do
puts "hello " + name
end
end
end
And I get the following error:
`define_method': interning empty string (ArgumentError) in 'method_missing'
Any ideas? Thanks.
Edit:
I got it working a different way, but I'm still curious how to do it this way. Here is my code:
def method_missing(meth,*args,&block)
Adder.class_eval do
define_method(meth) do
puts "hello " + meth
end
end
send("#{meth}")
end