From: Nilesh Trivedi Date: 2009-09-10T21:35:09+09:00 Subject: defining a singleton method dynamically --000e0cd6d132917be00473386dfd Content-Type: text/plain; charset=ISO-8859-1 How do I define a singleton method dynamically? I have code similar to this: def foo(obj,label) 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 which expects this singleton method in obj end When I try to run this as foo(Object.new,"xyz"), it throws a "NameError: undefined local variable or method `label' for #" whereas I want it to print "xyz" to screen. Of course, line 2 in method foo is not correct. But what is the correct way? --000e0cd6d132917be00473386dfd--