x + y
is syntactic sugar for
x.send(:+, y)
What is this a syntactic sugar for?
x += y
I've tried
x.send(:+=, y)
but it doesn't work
A method in Ruby is a set of expressions that returns a value. Within a method, you can organize your code into subroutines which can be easily invoked from other areas of their program. A method name must start a letter or a character with the eight-bit set.
From ruby's perspective Methods are Objects. The implementation details are not important. A method can be addresses and passed just like any other object.
In Ruby, the at-sign ( @ ) before a variable name (e.g. @variable_name ) is used to create a class instance variable.
It is not a method. It is a short way (syntactic sugar) for writing following:
x = 1
#=> 1
x += 1 # same as x = x + 1
#=> 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With