something.each do |x|
#lots of stuff
end if some_condition
something.each do |x|
#lots of stuff
end if some_condition
I'd personally advocate against that for the pure and simple reason that it is too easy to miss. Even with that shortened version it took me a double-take to realise you had the
if some_condition
at the end
In the organization I work for we have started to flag such constructs for re-write.
I think the above example is perfectly fine in certain cases where it exists inside of several nested blocks. If the above code is 4 levels deep then you have eliminated another level. Therefore, in certain cases, the above style can actually increase readability. Note we are assuming that there are no more than 20 statements within the block.
I almost never use the modifier forms of conditionals because I think there is too much potential for reader confusion. It's like an officer talking to a subordinate:
<sergeant> Your orders are to climb that hill and recon the enemy! <private> YES SIR! *begins running up the hill* <sergeant> ... but only if you have binoculars.
The only time I might consider it acceptable is when the thing modified is so small that the conditional can clearly be seen, e.g.
do loop # ... next if condition # ... end
Long code block it self is a bad practice, refactor it to more smaller blocks.
Modifier after a long block is a way to hell.
I think the popular way is to use statement modifiers only if it is a one-liner. In all other cases, use the normal if style prevalent in C, Java etc.
bail_out if reqd_param.nil?
if its_gonna_be_long then
long_exec stmt1
long_exec stmt2
....
end