From: 7stud -- Date: 2009-09-19T11:14:26+09:00 Subject: Re: Mucking about with dynamically adding methods to objects 7stud -- wrote: > > ...but if you try this: > > > def talkify(obj, str) > obj_singleton = get_singleton_class(obj) > > obj_singleton.class_eval %Q{ > > def talk > puts str #<---CHANGE HERE**** > end > > } > > end > > > ...it doesn't work. The def creates a new scope, and str is not defined > inside the def. > To be clearer, that should read: ...it doesn't work. When the string is evaluated inside the singleton class, the def creates a new scope, and the str variable is not defined inside the def. -- Posted via http://www.ruby-forum.com/.