From: Ben Tilly Date: 2001-03-04T10:57:33+09:00 Subject: [ruby-talk:11959] Re: singleton classes? Dave Thomas wrote: > >"Ben Tilly" writes: > > > Can someone give me an example of how you would write a method that > > extends an object and gives it a new method? (I kept on seeing > > "nested method definition" warnings when I tried it the naive way.) > >Ben, > >Do you mean this, or are you looking for something more subtle that >I'm (yet again) missing. > Erm... > > def empower(anObj) > def anObj.gotThePower? > puts "I feeel the power" > end > end > > a = "downtrodden" > empower(a) > a.gotThePower? #=> I feeel the power Don't let occasional strokes of brilliance on my part lead you to believe that I lack the ability to also be a complete moron. Gads, I saw and used that, then forgot that, then when I was seeing the: class << anObject ... end syntax I forgot I already knew how to do that, tried to use it, failed miserably, then got confused. Thanks, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com