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

> I'm a little curious about why, to you, boolean methods are "relevant"
> and other methods are not.  For that explanation, I would have just said
> that methods are not objects -- rather than saying something like
> "boolean methods aren't objects; let's not talk about other methods
> (which also aren't, but we shouldn't say that)".
>
>
Sorry, I wasn't very clear, it's a difficult subject to talk about because
the language is largely ambiguous.

Apparently, methods are *technically* not objects. Roger already brought it
up above, and it's been discussed before (
http://www.ruby-forum.com/topic/424911). Now, given that we can request a
method, and get an instance of Method, lets disregard this as it seems to me
to be an implementation detail.

So we can say that methods are objects, and everything suddenly makes sense
again. Operators are methods, and methods are objects, so operators are
objects. Except for boolean operators, which are not methods and thus not
objects. They are basically keywords. Here are some examples:


You can't define || or && on your object.
class Foo
  def &(other)
    "foo and #{other}"
  end
end
Foo.new & 'bar' # => "foo and bar"

class Foo
  def &&(other)
    "foo and and #{other}"
  end
end
Foo.new && 'bar' # ~> -:9: syntax error




You can't request them as methods, and thus can't pass them as arguments or
put them into block slots or store them in variables.
true.method '&' # => #<Method: TrueClass#&>
true.method '&&' # ~> -:1:in `method': undefined method `&&' for class
`TrueClass' (NameError)



With normal operators you can do fun stuff like this
plus_ten = 10.method('+')
[1,2,3,4,5].map(&plus_ten) # => [11, 12, 13, 14, 15]
But you can't do anything like that with &&, because it's not a method.




I was thinking about it just now, and realized assignment methods are the
same way. For example, you can't define +=