Hey everyone!
Maybe it’s just a pure style thing but I prefer to use Conditional Assignments as “assign_inside_condition” like:
if foo
bar = 1
else
bar = 2
end
case foo
when 'a'
bar += 1
else
bar += 2
end
if foo
some_method
bar = 1
else
some_other_method
bar = 2
end
It is super easy to read and there are no surprises with assignations.
However … I’m using Rubocop and it seems it supports both assign_to_condition and assign_inside_condition. And I started to wondering if there is any real advantage of using assign_to_condition
… In my very own personal opinion I find this a bit ugly and hard to read … but maybe I’m wrong …
Maybe I’m just not happy having it like:
bar = if foo
1
else
2
end
bar += case foo
when 'a'
1
else
2
end
bar << if foo
some_method
1
else
some_other_method
2
end
What do you guys think? And What do you usually use?
Rubocop ConditionalAssignments
Thanks!