提交 c0b4db0c 编写于 作者: G Gabriel Horner 提交者: Santiago Pastorino

fix OrderedHash#each* methods to return Enumerators when called without a...

fix OrderedHash#each* methods to return Enumerators when called without a block [#6366 state:resolved]
Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 bca070ef
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册