From: dblack@... Date: 2007-01-07T01:23:23+09:00 Subject: Re: Getting existing context when defining a singleton method (class << obj) Hi -- On Sun, 7 Jan 2007, Roland Swingler wrote: > Hi > > I'm fairly new to this "meta-programming" thing, so excuse me if I get > my terminology wrong. Is there any way of getting access to the > exisiting context when using class << obj or otherwise creating a > singleton method? Yes: sclass = (class << obj; self; end) sclass.class_eval do define_method ... end That will keep you in the local scope you started in. Hopefully there will be a method in Ruby 1.9/2.0 that will let you grab an object's singleton class, so you could do: obj.singleton_class.class_eval # etc. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)