Ruby Array Intersection Issue -


i've been attempting intersect array using "&" interesection method twitter api in ruby. i've tried several different ways , says... "undefined method `&' twitter...". same "|" , "-". documentation i've read says need use "&" intersect arrays , new array values of same values. i'm new ruby, missing?...

@var = @array1 & @array2 

my controller code below:

class userscontroller < actioncontroller::base     def index       redirect_to :controller => 'users', :action => 'show', :id => params[:id]    end     def show       begin         @users = $client.user_timeline(params[:id])[0..9] #gets last 10 tweets         @userinfo = $client.user(params[:id])         @friends = $client.friend_ids(@userinfo.id)       rescue twitter::error::notfound           redirect_to :controller => 'users', :action => 'show', :id => '404'       end   end    def compare       @users = $client.user_timeline(params[:id])[0..0] #limits timeline request 1       @users2 = $client.user_timeline(params[:id2])[0..0] #limits timeline request 1       @userinfo = $client.user(params[:id])       @userinfo2 = $client.user(params[:id2])        @friendlists = $client.friend_ids(@userinfo.id) #variable 1       @friendlists2 = $client.friend_ids(@userinfo2.id) #variable 2   end  end  

my view code is...

<% @friendmerge = @friendlists & @friendlists2 %> #<--this should work right?  <% if !@friendmerge.blank? %>    <pre><%= json.pretty_generate(@friendmerge) %></pre>    <% else %>    didn't work. <% end %> 

i'm new ruby, please kind. realize may struggling few core principles. , appreciated.

if objects not support (array) intersection might still know how convert array does. try

@friendmerge = @friendlists.to_a & @friendlists2.to_a 

in order find out.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -