From: dblack@... Date: 2007-01-07T01:50:02+09:00 Subject: Re: Getting existing context when defining a singleton method (class << obj) Hi -- On Sun, 7 Jan 2007, Roland Swingler wrote: > Great! > >> Yes: > > Thanks for the (very speedy) response. > >> 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. > > I guess you can have this in ruby 1.8 by doing > > class Object > def singleton_class > class << self > self > end > end > end Yes, many of us have had occasion to write exactly that :-) > Some code that I've seen around is now much clearer... thanks again. Glad to help! 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)