Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Refactor into a class method. (http://www.velocityreviews.com/forums/t846569-refactor-into-a-class-method.html)

Ruby Geo 12-13-2007 03:53 PM

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 }
--
Posted via http://www.ruby-forum.com/.


Robert Klemme 12-13-2007 04:05 PM

Re: Refactor into a class method.
 
2007/12/13, Ruby Geo <rubyror@googlemail.com>:
> 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

--
use.inject do |as, often| as.you_can - without end



All times are GMT. The time now is 11:08 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.