How do I order a collection returned when I''ve accessed it from dot notation? For example using client.products I''d like the return to be ordered by product.part_number. I''ve tried to do this Ruby side with something like client.products.sort {|a, b| a.part_number > b.part_number} and I get an error. Any idea how to deal with this? Thanks, -dustin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 12/13/06, Dustin Withers <fadeddata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > How do I order a collection returned when I''ve accessed it from dot > notation? For example using client.products I''d like the return to be > ordered by product.part_number. I''ve tried to do this Ruby side with > something like client.products.sort {|a, b| a.part_number > > b.part_number} and I get an error. Any idea how to deal with this?products = client.products.find( :all, :order => [ ''part_number'' ] ) -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
FYI Your sort code was almost right: @products = client.products.sort {|a, b| b.part_number <=> a.part_number} would give you the products sorted high to low. On Dec 14, 7:16 am, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/13/06, Dustin Withers <fadedd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > How do I order a collection returned when I''ve accessed it from dot > > notation? For example using client.products I''d like the return to be > > ordered by product.part_number. I''ve tried to do this Ruby side with > > something like client.products.sort {|a, b| a.part_number > > > b.part_number} and I get an error. Any idea how to deal with this?products = client.products.find( :all, :order => [ ''part_number'' ] ) > > -- > Greg Donaldhttp://destiney.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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Dec-14 01:11 UTC
Re: Dot notation ordering
Hi -- On Thu, 14 Dec 2006, jdswift wrote:> On Dec 14, 7:16 am, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 12/13/06, Dustin Withers <fadedd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> How do I order a collection returned when I''ve accessed it from dot >>> notation? For example using client.products I''d like the return to be >>> ordered by product.part_number. I''ve tried to do this Ruby side with >>> something like client.products.sort {|a, b| a.part_number > >>> b.part_number} and I get an error. Any idea how to deal with this? >>> >> products = client.products.find( :all, :order => [ ''part_number'' ] ) >> > > FYI Your sort code was almost right: > @products = client.products.sort {|a, b| b.part_number <=> > a.part_number} > > would give you the products sorted high to low. >Or the slightly more concise: @products = client.products.sort_by {|prod| prod.part_number } 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 -~----------~----~----~----~------~----~------~--~---
On 12/13/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > Hi -- > > On Thu, 14 Dec 2006, jdswift wrote: > > > On Dec 14, 7:16 am, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 12/13/06, Dustin Withers <fadedd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >>> How do I order a collection returned when I''ve accessed it from dot > >>> notation? For example using client.products I''d like the return to be > >>> ordered by product.part_number. I''ve tried to do this Ruby side with > >>> something like client.products.sort {|a, b| a.part_number > > >>> b.part_number} and I get an error. Any idea how to deal with this? > >>> > >> products = client.products.find( :all, :order => [ ''part_number'' ] ) > >> > > > > FYI Your sort code was almost right: > > @products = client.products.sort {|a, b| b.part_number <=> > > a.part_number} > > > > would give you the products sorted high to low. > > > > Or the slightly more concise: > > @products = client.products.sort_by {|prod| prod.part_number }Or the slightly more concise: @products = client.products.sort_by &:part_number ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 12/13/06, Jeremy Evans <jeremyevans0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @products = client.products.sort_by &:part_numberWhere is this behavior documented? Thanks, -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
On 12/14/06, Greg Donald <gdonald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > @products = client.products.sort_by &:part_number > > Where is this behavior documented?Nevermind, I found it:> cat /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/symbol.rbclass Symbol # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: # # # The same as people.collect { |p| p.name } # people.collect(&:name) # # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } # people.select(&:manager?).collect(&:salary) def to_proc Proc.new { |obj, *args| obj.send(self, *args) } end end -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Excellent. Thank you all for the great answers... -dustin --~--~---------~--~----~------------~-------~--~----~ 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-15 01:17 UTC
Re: Dot notation ordering
Hi -- On Thu, 14 Dec 2006, Greg Donald wrote:> > On 12/14/06, Greg Donald <gdonald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> @products = client.products.sort_by &:part_number >> >> Where is this behavior documented? > > Nevermind, I found it: > >> cat /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/symbol.rb > > class Symbol > # Turns the symbol into a simple proc, which is especially useful > for enumerations. Examples: > # > # # The same as people.collect { |p| p.name } > # people.collect(&:name) > # > # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } > # people.select(&:manager?).collect(&:salary) > def to_proc > Proc.new { |obj, *args| obj.send(self, *args) } > end > endIt''s also in the development version of Ruby (1.9): $ /usr/local/lib/ruby-cvs/bin/ruby -ve ''p %w{ a b c }.map(&:upcase)'' ruby 1.9.0 (2006-12-09 patchlevel 0) [i686-linux] ["A", "B", "C"] 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 -~----------~----~----~----~------~----~------~--~---