Hi, My hash contain key as a combination of album date created_at and album_id and values are some photo object.and i need to sort this hash based on key; but i need to sort it also considering date created_at. but if i consider a key as combination of both (date creataed and album_id) then it is not pure date. how i solve it? any better solution -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Would you mind posting an example of the hash and an example of how you would like it sorted? Thanks, Josh http://iammrjoshua.com Sunny Bogawat wrote:> Hi, > > My hash contain key as a combination of album date created_at and > album_id and values are some photo object.and i need to sort this hash > based on key; but i need to sort it also considering date created_at. > but if i consider a key as combination of both (date creataed and > album_id) then it is not pure date. how i solve it? any better solution-- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Joshua Abbott wrote:> Would you mind posting an example of the hash and an example of how you > would like it sorted? > > Thanks, > Josh > http://iammrjoshua.comsay i have album id 233 and created date 12/09/2008 so my key should be 12092008_233 in this way? -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Sunny Bogawat wrote:> Joshua Abbott wrote: >> Would you mind posting an example of the hash and an example of how you >> would like it sorted? >> >> Thanks, >> Josh >> http://iammrjoshua.com > > > say i have album id 233 and created date 12/09/2008 so my key should be > 12092008_233 in this way?Instead of concatenating a string, just make your key an array of the values. hash = {} key = [date, album_id] hash[key] = value However, hashes are not sorted in Ruby 1.8. Rails 2.x has an OrderedHash that maintains the keys'' nsertion order, but it''s not efficient for lookup by key. If you only plan to use the hash for iteration, that''s probably OK (but then why use a hash?). -- Posted via http://www.ruby-forum.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 Dec 27, 4:18 pm, Jeremy Weiskotten <rails-mailing-l...@andreas- s.net> wrote:> hash = {} > key = [date, album_id] > hash[key] = value > > However, hashes are not sorted in Ruby 1.8. Rails 2.x has an OrderedHash > that maintains the keys'' nsertion order, but it''s not efficient for > lookup by key. If you only plan to use the hash for iteration, that''sOrderedHash is a lot speedier in 2.3 Fred> probably OK (but then why use a hash?). > -- > Posted viahttp://www.ruby-forum.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Dec 27, 4:18�pm, Jeremy Weiskotten <rails-mailing-l...@andreas- > s.net> wrote: >> hash = {} >> key = [date, album_id] >> hash[key] = value >> >> However, hashes are not sorted in Ruby 1.8. Rails 2.x has an OrderedHash >> that maintains the keys'' nsertion order, but it''s not efficient for >> lookup by key. If you only plan to use the hash for iteration, that''s > > OrderedHash is a lot speedier in 2.3 > > FredGood to know, although I''m not even on 2.2 yet due to plugin incompatibilities. Thanks! -- Posted via http://www.ruby-forum.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, Dec 27, 2008 at 8:28 AM, Jeremy Weiskotten <rails-mailing-list@andreas-s.net> wrote:> > Frederick Cheung wrote: >> On Dec 27, 4:18�pm, Jeremy Weiskotten <rails-mailing-l...@andreas- >> s.net> wrote: >>> hash = {} >>> key = [date, album_id] >>> hash[key] = value >>> >>> However, hashes are not sorted in Ruby 1.8. Rails 2.x has an OrderedHash >>> that maintains the keys' nsertion order, but it's not efficient for >>> lookup by key. If you only plan to use the hash for iteration, that's >> >> OrderedHash is a lot speedier in 2.3 >> >> Fred > > Good to know, although I'm not even on 2.2 yet due to plugin > incompatibilities. Thanks! >Jeremy, I apologize if this was already considered, but you *can* sort a hash by a key/value, but it's not inherently sorted for you. * http://www.oreillynet.com/ruby/blog/2005/12/sorting_an_array_of_hashes_wit_2.html Good luck! Cheers, Robby -- Robby Russell Chief Evangelist, Partner PLANET ARGON, LLC design // development // hosting http://www.planetargon.com/ http://www.robbyonrails.com/ aim: planetargon +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4068 [fax] --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---