On Fri, Apr 29, 2011 at 2:37 PM, Chad Perrin <code / apotheon.net> wrote:

> > >     puts.extend Enumerable
> >
> > That, of course works, puts evalutaes to nil, nil is an object and
> therefore
> > has a singleton class, and therefore can be extended.
>
> It doesn't extend puts; puts is not an object.  Trying to think of puts
> as an object doesn't work.  It gives surprising results if you actually
> expect it to behave as an object in and of itself, thus violating the
> "objects and methods" model of Ruby.
>
>
>
That's because methods are invoked by default, as I already stated. You need
a line that evaluates to the method, not to nil. Your issue isn't with the
objectivity of methods, it is with how you access methods.

# this is evaluated
puts                            # => nil

# now we have a reference to it
puts = method :puts             # => #<Method: Object(Kernel)#puts>

# and look, we can extend it
puts.extend Enumerable          # => #<Method: Object(Kernel)#puts>
puts.singleton_class.ancestors  # => [Enumerable, Method, Object, Kernel,
BasicObject]