What does
->
signify in above example?
->
is part of the literal syntax for lambdas, just like, say, '
is part of the literal syntax for strings.
Is the
.call
method just passing the value from to caller,
The call
method is the method, which, well, calls (or executes) the lambda. The arguments to the call
method are bound to the parameters of the lambda.
so in first example value
y
is passed toy
and in second example1
is passed tox
.
No, in the first example, y
is passed to the outer lambda and bound to its x
parameter. In the second example, 1
is passed to the lambda and bound to its x
parameter.
In second example why how is
1
evaluated tox
?
1
does not evalute to x
. 1
is an immediate value, and in Ruby, immediate values always evaluate to themselves. 1
will always evaluate to 1
, never to x
or anything else.