Refactor into a class method

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 }

2007/12/13, Ruby G. [email protected]:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs