# Search Array

**URL:** <https://rubytalk.org/t/search-array/42982>\
**Category:** ruby-talk\
**Created:** [13 December 2007 15:15 UTC](https://rubytalk.org/t/search-array/42982 "2007-12-13T15:15:53Z")\
**Posts on this page:** 1\
**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:15 UTC](https://rubytalk.org/t/search-array/42982/1 "2007-12-13T15:15:53Z")

</div>

Hi all.

I am trying to convert the folowing code into a class method. which  
takes two argument. ! for keywords and another for business(callection  
of classes). which both are arrays. And I am stack any help ? ?

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 }

'''''''''''''''''''''''''''''''''''''''''''''''''''

Attemted method

&nbsp;&nbsp;&nbsp;def self.search\_type(key ,user)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objects = [bsn0, bsn1, bsn2, bsn3, bsn4]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#search = ["Sole Trader"]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#search = [KEYWORDS[0],KEYWORDS[1],KEYWORDS[2],KEYWORDS[3]]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results = objects.select do |b|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b.my\_keywords.include?(search[0])

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;end

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