On Thu, Apr 28, 2011 at 10:40 PM, Chad Perrin <code / apotheon.net> wrote:

> On Fri, Apr 29, 2011 at 08:39:14AM +0900, Josh Cheek wrote:
> > On Thu, Apr 28, 2011 at 3:22 PM, Chad Perrin <code / apotheon.net> wrote:
> > >
> > > Oh, you're talking about boolean operators.  I thought you were talking
> > > about actual boolean *methods*:
> > >
> > >    irb(main):001:0> foo = Hash.new
> > >    => {}
> > >    irb(main):002:0> foo.empty?
> > >    => true
> >
> > I think of operators as methods. Probably the best term for those is
> > predicate.
>
> Thinking of them as methods is probably a bad idea.  It may lead you to
> make unwarranted assumptions about things you can do with them.
>
>
Can you be more explicit? They are methods, I don't understand what you
mean.



> > I'm not saying that methods are objects, I'm saying that calling them
> > non-objects serves no purpose, and choosing to think of them as objects
> (as
> > Ruby obviously wants you to) allows Ruby to be elegant again.
>
> It's perfectly "elegant" in terms of a consistent model without
> mislabeling methods as objects.  Ruby does not seem to "want" me to think
> of methods as objects, else stuff like this would be meaningful
>
>    puts.extend Enumerable
>    puts.class
>    foo(puts)
>
>
Those are meaningful, if you are interested in what the method returns
(nil). If you are interested in the method, then don't invoke it. Since
listing the method's name is syntactic sugar for invoking it, then how do
you get the method? Just ask for it method(:puts).extend(Enumerable)


On Thu, Apr 28, 2011 at 10:45 PM, Chad Perrin <code / apotheon.net> wrote:

> >
>  > Do you have a real world example of that?  Perhaps:
> >
> > (1, 2, 3).send(:ancestors)
>
>     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.

puts # => nil
puts.singleton_class.ancestors # => [NilClass, Object, Kernel, BasicObject]
puts.extend Enumerable
puts.singleton_class.ancestors # => [NilClass, Enumerable, Object, Kernel,
BasicObject]