> From: Ben Tilly [mailto:ben_tilly / hotmail.com]
[...]

> >Sometimes it's simply a notational convenience. Othertimes, you
> >genuinely need to be able to add features to objects.[...]
> >
> >I have to admit I use this rarely, but it's always a nice solution to
> >have in your back pocket.
> 
> I actually tried putting this in my back pocket a while
> ago, and failed.
> 
> 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.)
Since methods are not objects you will have hard time
doing this (I know you can create a method object but
this is not the same thing).

Probably the closed is the #extend method from Object -
for example.
 
module Bla
def do_nothing
end
def also_useless
end

x = Object.new
x.extend Bla

x.do_nothing
x.also_useless

Christoph
 
[...]
>