Permalink
Browse files

fix OrderedHash#each* methods to return Enumerators when called witho…

…ut a block [#6366 state:resolved]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent bca070e commit c0b4db0c28465866b656c894c16ce35f4d313a12 @cldwalker cldwalker committed with spastorino Feb 3, 2011
Showing with 9 additions and 0 deletions.
  1. +3 −0 activesupport/lib/active_support/ordered_hash.rb
  2. +6 −0 activesupport/test/ordered_hash_test.rb
@@ -137,16 +137,19 @@ def to_a
end
def each_key
+ return to_enum(:each_key) unless block_given?
@keys.each { |key| yield key }
self
end
def each_value
+ return to_enum(:each_value) unless block_given?
@keys.each { |key| yield self[key]}
self
end
def each
+ return to_enum(:each) unless block_given?
@keys.each {|key| yield [key, self[key]]}
self
end
@@ -80,18 +80,24 @@ def test_each_key
keys = []
assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k }
assert_equal @keys, keys
+ expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator
+ assert_kind_of expected_class, @ordered_hash.each_key
end
def test_each_value
values = []
assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v }
assert_equal @values, values
+ expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator
+ assert_kind_of expected_class, @ordered_hash.each_value
end
def test_each
values = []
assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value}
assert_equal @values, values
+ expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator
+ assert_kind_of expected_class, @ordered_hash.each
end
def test_each_with_index

0 comments on commit c0b4db0

Please sign in to comment.