2 ms·
It's not the method that's special, per se, but the `=` operator. The `=` operator always returns the right operand, discarding whatever is returned from the se
by chc 14y ago
It's not the method that's special, per se, but the `=` operator. The `=` operator always returns the right operand, discarding whatever is returned from the setter method. AFAIK it's because that's the expected behavior when you're doing chained assignments. You wouldn't normally want the leftmost operand in `a = b = c` to get a weird value just because the middle operand internally does some transformation, so the `=` operator yields the right operand unaltered.
If you went directly through the method (e.g. `t.send(:attr=, 5)` or `t.method(:attr=).call 5`), you'd get 10.
- Denzel 14y agoThanks for the explanation chc, and grn. Indeed, invoking the method indirectly with send or method does produce 10. Nice!