How do I define a singleton method dynamically?
I have code similar to this:
def obj.name; label; end #we want to define a singleton method called
“name” on obj which returns the value in label
puts obj.name #this is an example. Actually I have some code here
expects this singleton method in obj
When I try to run this as foo(Object.new,“xyz”), it throws a “NameError:
undefined local variable or method `label’ for #Object:0xb7b02018”
I want it to print “xyz” to screen.
Of course, line 2 in method foo is not correct. But what is the correct