Operator Expressions

Can anyone explain the following line of code?

(a.*(b)).+© # => 5

The textbook did not elaborate regarding the purpose of the period after
the letter “a” and the big parentheses surrounding letters “a” and “b”.

Bruce H. wrote in post #1175985:

Can anyone explain the following line of code?

(a.*(b)).+© # => 5

The textbook did not elaborate regarding the purpose of the period after
the letter “a” and the big parentheses surrounding letters “a” and “b”.

in ruby all things are object and method. so operator does not
exists, there are syntaxics sugar :
a + b is translated to a.add(b) , but in place of ‘add’, the methode
name is ‘+’.

so a+b is realy a.+(b)

so if you use
ab+c
the interpreter will anderstand (a.
(b)).+©
cqfd :slight_smile:

you.do?(:anderstood)

To add to the response by raubarede:

The parentheses around b are redundant in this example.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs