Ruby Trick: Local Assignment over Method Sending
There is a weird situation I haven’t noticed before:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Why the hell?
Local assignment always has precedence over method sending. Assignment happened in w.foo
, which not in w.bar
.
Check this one:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
name = 'John'
only means a definition of a local variable, which won’t send =
to name
.