The usual convention is { ... } blocks for single-line and do ... end for multi-line. I usually follow this convention, but should I ever be king, I think I would use do .. end more often.
The random problem with {} is that {} bound more tightly than do end , so the only way to write a poetry style block for a method that also has parameters is to use do end , otherwise the block will be part of the parameter and will not be passed directly to the method.
def fx yield x end f 123 do |n| pn end
Of course, if you want to attach a block to a parameter in poetry mode, then you will win with {} , followed by a do end .
def g ; p ['g', yield] end def fx; p ['f', yield] end fg { 2 } do 3 end ["g", 2] ["f", 3]
Lastly, and unlike some of the tips you got here ; not required until end .
Digitaloss
source share