# Refactor into a class method

**URL:** <https://rubytalk.org/t/refactor-into-a-class-method/42985>\
**Category:** ruby-talk\
**Created:** [13 December 2007 15:53 UTC](https://rubytalk.org/t/refactor-into-a-class-method/42985 "2007-12-13T15:53:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruby\_Geo](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@Ruby\_Geo](https://rubytalk.org/u/Ruby_Geo)\
**Post date:** [13 December 2007 15:53 UTC](https://rubytalk.org/t/refactor-into-a-class-method/42985/1 "2007-12-13T15:53:18Z")

</div>

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

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [13 December 2007 16:05 UTC](https://rubytalk.org/t/refactor-into-a-class-method/42985/2 "2007-12-13T16:05:27Z")

</div>

> objects = [bsn0, bsn1, bsn2, bsn3, bsn4]  
> search = ["Sole Trader"]  
> results = objects.select do |b|  
> &nbsp;&nbsp;match = true  
> &nbsp;&nbsp;catch(:success) do  
> &nbsp;&nbsp;&nbsp;&nbsp;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.

> &nbsp;&nbsp;&nbsp;&nbsp;match = false  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;match
> 
> end  
> puts (" ")  
> puts "Search Results"  
> puts (" ")  
> results.each{|r| puts r }

What was the question again?

robert

> **···**
>
> 2007/12/13, Ruby Geo \<rubyror@googlemail.com\>:
> 
> --  
> use.inject do |as, often| as.you\_can - without end
