P
Pat Maddox
I don't have any practical use for this, but I was experimenting a bit.
I just want to create singleton methods on objects of this class.
There's more to come, but this is the part I'm stuck at
This code doesn't actually work, but I think it's close (I hope?)
class OneShot
def method_missing(m)
class << self
define_method(m) { puts m.to_s }
end
send(m)
end
end
When I do this I get "NameError: undefined local variable or method `m'
for #<Class:#<OneShot:0x32cf74>>" so I think it means that m just isn't
in scope for the singleton class. How can I define the singleton
method? Is there any way to use binding here?
Pat
I just want to create singleton methods on objects of this class.
There's more to come, but this is the part I'm stuck at
This code doesn't actually work, but I think it's close (I hope?)
class OneShot
def method_missing(m)
class << self
define_method(m) { puts m.to_s }
end
send(m)
end
end
When I do this I get "NameError: undefined local variable or method `m'
for #<Class:#<OneShot:0x32cf74>>" so I think it means that m just isn't
in scope for the singleton class. How can I define the singleton
method? Is there any way to use binding here?
Pat