Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Refactor into a class method.

Reply
Thread Tools

Refactor into a class method.

 
 
Ruby Geo
Guest
Posts: n/a
 
      12-13-2007
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/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-13-2007
2007/12/13, Ruby Geo <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converted ASP.NET project: Refactor pages Steven Nagy ASP .Net 1 10-16-2006 01:17 PM
Refactor a buffered class... lh84777@yahoo.fr Python 12 09-14-2006 06:30 AM
Refactoring old tags: Tag Files (re: mother of a refactor) VisionSet Java 3 08-08-2006 08:28 AM
Mother of a Refactor VisionSet Java 11 08-01-2006 10:25 PM
Ruby script to Module/Class refactor James B. Byrne Ruby 10 02-24-2006 06:42 PM



Advertisments