DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Too Small For Function, Too Big To Be Un-DRY
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!






Comments
Snippets Manager replied on Sat, 2006/09/09 - 4:19pm