[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

collect results if no block given

Martin DeMello

1/2/2005 7:17:00 PM

Fairly trivial, but it took me a couple of rounds of refactoring to hit
upon, so I thought I'd share it

def collect_nodes(index, set)
a = []
find_nodes(index, set) {|node| a << node}
a
end

def find_nodes(index, set)
return collect_nodes(index, set) unless block_given?
[rest of method]
end

Got rid of a lot of if block_given? clutter in the second method.

martin