collect results if no block given

M

Martin DeMello

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top