Too Small For Function, Too Big To Be Un-DRY
Join the DZone community and get the full member experience.Join For Free
I wanted to execute the same block of code twice in the same procedure, but the block itself I did not feel warranted its own function (this was in a Rails test). So here's a neat trick to keep it DRY:
p = Proc.new do r1 = Record.find 1 r2 = Record.find 2 r3 = Record.find 3 end p.call # ... do some useful stuff ... p.call # do it again!
Opinions expressed by DZone contributors are their own.