mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActiveSupport::OrderedHash#to_a method returns an ordered set of arrays. Matches ruby1.9's Hash#to_a.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#2629 state:committed]
This commit is contained in:
parent
235775de29
commit
9e0cfdb7f9
2 changed files with 8 additions and 0 deletions
|
@ -57,6 +57,10 @@ module ActiveSupport
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_a
|
||||||
|
@keys.map { |key| [ key, self[key] ] }
|
||||||
|
end
|
||||||
|
|
||||||
def each_key
|
def each_key
|
||||||
@keys.each { |key| yield key }
|
@keys.each { |key| yield key }
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,6 +51,10 @@ class OrderedHashTest < Test::Unit::TestCase
|
||||||
assert_same @ordered_hash, @ordered_hash.to_hash
|
assert_same @ordered_hash, @ordered_hash.to_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_to_a
|
||||||
|
assert_equal @keys.zip(@values), @ordered_hash.to_a
|
||||||
|
end
|
||||||
|
|
||||||
def test_has_key
|
def test_has_key
|
||||||
assert_equal true, @ordered_hash.has_key?('blue')
|
assert_equal true, @ordered_hash.has_key?('blue')
|
||||||
assert_equal true, @ordered_hash.key?('blue')
|
assert_equal true, @ordered_hash.key?('blue')
|
||||||
|
|
Loading…
Reference in a new issue