I want to make an array out of the difference of two different arrays I have an array of users who own a page @page.users I want the array of the users who do not own the page Example: @page.users = [kim, bob, sue] and @users = User.find(:all) = [kim, bob, sue, joe, jim] then I want the difference between the two @not_page_users = [joe, jim] Thanks in advance -- K --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Johnston
2006-Dec-22 00:58 UTC
Re: Creating a array from the difference of two arrays
Built in to the Array class. Array defines - to do exactly that non_owners = @users - @page.users (google ruby array difference) Cheers Michael Johnston On 21-Dec-06, at 4:50 PM, Kim wrote:> > I want to make an array out of the difference of two different arrays > > I have an array of users who own a page > @page.users > > I want the array of the users who do not own the page > > Example: > > @page.users = [kim, bob, sue] > > and > > @users = User.find(:all) = [kim, bob, sue, joe, jim] > > then I want the difference between the two > > @not_page_users = [joe, jim] > > Thanks in advance -- K > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@not_page_users = @users - @page.users thats all --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kim wrote:> > I want to make an array out of the difference of two different arrays > > I have an array of users who own a page > @page.users > > I want the array of the users who do not own the page > > Example: > > @page.users = [kim, bob, sue] > > and > > @users = User.find(:all) = [kim, bob, sue, joe, jim] > > then I want the difference between the two > > @not_page_users = [joe, jim]Would you believe?: @not_page_users = @users - @page.users Here''s an example of where I think it would be really beneficial for those people coming to Rails without a lot of Ruby experience to either pick up a copy of the Pickaxe book or browse the contents of www.ruby-doc.org. If you go to ruby-doc.org, click on "core library" and click on "Array", you will be amazed at how many awesome methods Ruby already has that make stuff like this so easy. Hope I didn''t come across as lecturing you (or anyone else). I just would hate to see Rails users who don''t know much Ruby miss out on using the power of such an awesome programming language. Jamey --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wow. I am feeling pretty stupid right now. Jamey, You are right. I am new to Ruby and Rails and often forget that Ruby is a powerful language. I get confused on what is rails and what is ruby and where to look for what. I actually do visit the Rails API often but not the Ruby docs. I will now! Thanks to everyone. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Dec-22 03:21 UTC
Re: Creating a array from the difference of two arrays
Hi -- On Thu, 21 Dec 2006, Jamey Cribbs wrote:> Would you believe?: > > @not_page_users = @users - @page.users > > > Here''s an example of where I think it would be really beneficial for those > people coming to Rails without a lot of Ruby experience to either pick up a > copy of the Pickaxe book or browse the contents of www.ruby-doc.org. > > If you go to ruby-doc.org, click on "core library" and click on "Array", you > will be amazed at how many awesome methods Ruby already has that make stuff > like this so easy. > > Hope I didn''t come across as lecturing you (or anyone else). I just would > hate to see Rails users who don''t know much Ruby miss out on using the power > of such an awesome programming language.I agree whole-heartedly :-) David -- Q. What''s a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kim - I would order David''s book :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---