Permalink
Browse files

ActiveSupport::OrderedHash#to_a method returns an ordered set of arra…

…ys. Matches ruby1.9's Hash#to_a.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2629 state:committed]
  • Loading branch information...
metaskills authored and NZKoz committed May 9, 2009
1 parent 235775d commit 9e0cfdb7f951c0446cdfd3b2cc26443712fe657a
Showing with 8 additions and 0 deletions.
  1. +4 −0 activesupport/lib/active_support/ordered_hash.rb
  2. +4 −0 activesupport/test/ordered_hash_test.rb
@@ -57,6 +57,10 @@ def to_hash
self
end
+ def to_a
+ @keys.map { |key| [ key, self[key] ] }
+ end
+
def each_key
@keys.each { |key| yield key }
end
@@ -51,6 +51,10 @@ def test_to_hash
assert_same @ordered_hash, @ordered_hash.to_hash
end
+ def test_to_a
+ assert_equal @keys.zip(@values), @ordered_hash.to_a
+ end
+
def test_has_key
assert_equal true, @ordered_hash.has_key?('blue')
assert_equal true, @ordered_hash.key?('blue')

1 comment on commit 9e0cfdb

Contributor

metaskills commented on 9e0cfdb May 10, 2009

Hmmm... never considered that I could have just zip'ed the values in the implementation method as well. Oh well, thanks for getting this in so fast! :)

Please sign in to comment.