Re:Why Does “=” Mean Assignment?
by lloeki on Tuesday April 10, 2018 @05:23PM
(#16805590)
There is a Ruby idiom[0] that I find quite useful (esp. combined with a linter such as Rubocop), leveraging optional parens as a marker of intentional assignment:
# bad
if v = array.grep(/foo/)
do_something(v)
# some code
end
# good
if (v = array.grep(/foo/))
do_something(v)
# some code
end
[0]: https://github.com/bbatsov/ruby-style-guide#safe-assignment-...