On Thu, Apr 28, 2011 at 4:48 AM, amir e. <aef1370 / gmail.com> wrote:

> Hi
> A very important principle in Ruby is that every thing is object.
> I read somewhere that there is no primitive operation in Ruby in
> traditional form and every operation is class.
> Now if every thing is object , then why   + , - , * , ^ , ^^   isn't
> class Although they are primitive operation ?
>
> ps : If you test these codes , error happen : +.class  -.class   *.class
>
>
Those are methods, the Ruby interpreter uses syntactic sugar to make them
look like operators.

1.methods.grep(/^[\W]/) # => [:-@, :+, :-, :*, :/, :%, :**, :==, :===, :<=>,
:>, :>=, :<, :<=, :~, :&, :|, :^, :[], :<<, :>>, :+@, :=~, :!~, :!, :!=]

(the leading colons means these are symbols, if you aren't familiar with
symbols, you can think of them as a slightly different type of string)



There are only three _relevant_ things that I can think of right now that
aren't objects. Let us say that a thing is relevant as a nonobject if it
means you can't manipulate it like an object (ie pass it as an argument,
store it in a variable, and call methods on it). The first is boolean
methods like "&&" and "||", the second is keywords like "class", and "def",
the third is variables, which point to objects but are not objects
themselves, thus cannot be pointed to by other variables.

Using my above definition of "relevant", it is *not* relevant that methods
and blocks aren't objects (in MRI), and I think it is better for your mental
health and your understanding of the language if you forget that particular
piece of pedantic trivia.