This project is archived and is in readonly mode.
OrderedHash .to_hash and .sort
Reported by Stephen Heuer | March 4th, 2009 @ 02:49 AM
Using ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.6.0]
It seems in rails 2.3 that .to_hash doesn't work, and .sort now returns an array instead of an ordered hash.
Loading development environment (Rails 2.2.2)
>> ActiveSupport::OrderedHash.new([:one, :two])
=> [:one, :two]
>> ActiveSupport::OrderedHash.new([[:one, :two]])
=> [[:one, :two]]
>> h = ActiveSupport::OrderedHash.new
=> []
>> h[:one] = :two
=> :two
>> h.to_hash
=> {:one=>:two}
>> h.keys
=> [:one]
>> h.sort
=> [[:one, :two]]
>> h.sort.keys
=> [:one]
>> h.sort.class
=> ActiveSupport::OrderedHash
Loading development environment (Rails 2.3.0)
>> ActiveSupport::OrderedHash.new([:one, :two])
=> #<OrderedHash {}>
>> ActiveSupport::OrderedHash.new([[:one, :two]])
=> #<OrderedHash {}>
>> h = ActiveSupport::OrderedHash.new
=> #<OrderedHash {}>
>> h[:one] = :two
=> :two
>> h.to_hash
=> {}
>> h.keys
=> [:one]
>> h.sort
=> [[:one, :two]]
>> h.sort.keys
NoMethodError: undefined method 'keys' for [[:one, :two]]:Array
from (irb):8
>> h.sort.class
=> Array
Comments and changes to this ticket
-
CancelProfileIsBroken March 4th, 2009 @ 01:51 PM
- Assigned user set to Jeremy Kemper
- Milestone cleared.
Partially fixed in http://github.com/rails/rails/co... but
(a) The change to to_hash introduced
SystemStackError: stack level too deep
into inspect
(b) Sort still behaves differently than it did in 2.2.2.
HOWEVER - the original 2.3.0 behavior under ruby 1.8 is consistent with the way OrderedHash behaves in 1.9:
irb(main):001:0> h = Hash.new => {} irb(main):002:0> h[:one] = :two => :two irb(main):003:0> h.keys => [:one] irb(main):004:0> h.sort => [[:one, :two]] irb(main):005:0> h.sort.keys NoMethodError: undefined method `keys' for [[:one, :two]]:Array from (irb):5 from /Users/mike/.rubies/1.9.T/bin/irb:12:in `<main>' irb(main):006:0> h.sort.class => Array
Probably the commit should just be reverted and the 2.2.2 behavior considered a bug.
-
Jeremy Kemper March 5th, 2009 @ 12:51 AM
- State changed from new to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>