Greetings,
Please see these operations:
irb(main):016:0> 3.+(4)
=> 7
irb(main):017:0> 3 + 4
=> 7
We can call the method with dot (".") or space interval.
You can do that because '+' is an operator. Whose behaviour it is
possible to define, for any class, in the body of a method. But its
ability to be interpreted in
3 + 4
is given by the fact that it is included in the (short) list of
operators. You can see the list by downloading the source of the Ruby
interpreter and looking at file doc/syntax/precedence.rdoc.
irb(main):013:0> s echo "kato"
Traceback (most recent call last):
2: from /usr/bin/irb:11:in `<main>'
1: from (irb):13
NoMethodError (undefined method `echo' for main:Object)
'echo' is not an operator. So, in order to use it, you either type the
word by itself, and in this case the interpreter will try to find a
method called echo for the object that is your current scope. Or you
use the '.' operator, that allows tou to indicate to which object the
method you want to invoke belongs.
HTH
Carlo
···
Subject: Question about calling the method
Date: Sun 09 Jan 22 08:23:07PM +0800
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)