Refactor into a class method.

R

Ruby Geo

objects = [bsn0, bsn1, bsn2, bsn3, bsn4]
search = ["Sole Trader"]
results = objects.select do |b|
match = true
catch:)success) do
search.each{|s| throw :success if b.my_keywords.include?(s) }
match = false
end
match

end
puts (" ")
puts "Search Results"
puts (" ")
results.each{|r| puts r }
 
R

Robert Klemme

2007/12/13 said:
objects = [bsn0, bsn1, bsn2, bsn3, bsn4]
search = ["Sole Trader"]
results = objects.select do |b|
match = true
catch:)success) do
search.each{|s| throw :success if b.my_keywords.include?(s) }

^^^^^^^^
I suggest you use Enumerable#any? instead of #each here and throw away
the catch throw logic.
match = false
end
match

end
puts (" ")
puts "Search Results"
puts (" ")
results.each{|r| puts r }

What was the question again?

robert
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top