Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

OrderedHash .to_hash and .sort

#2123

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

Reported by Stephen Heuer · March 4th, 2009 @ 02:49 AM

State: resolved
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Low

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • 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.

    March 4th, 2009 @ 01:51 PM

  2. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to resolved

    March 5th, 2009 @ 12:51 AM