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
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
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?).
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
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!