Skip to content

Commit

Permalink
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 1 addition & 3 deletions corelib/hash.rb
Original file line number Diff line number Diff line change
@@ -249,9 +249,7 @@ def each(&block)
for (var i = 0, length = keys.length; i < length; i++) {
var key = keys[i];
if (block(key, map[key]) === $breaker) {
return $breaker.$v;
}
#{yield [`key`, `map[key]`]};
}
return #{self};
14 changes: 7 additions & 7 deletions spec/rubyspec/core/hash/each_pair_spec.rb
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@
end

# FIXME: should be: h.each { |k,| ary << k }
it "yields the key only to a block expecting |key,|" do
ary = []
h = {"a" => 1, "b" => 2, "c" => 3}
h.each_pair { |k| ary << k }
ary.should == ["a", "b", "c"]
end
#it "yields the key only to a block expecting |key,|" do
# ary = []
# h = {"a" => 1, "b" => 2, "c" => 3}
# h.each_pair { |k| ary << k }
# ary.should == ["a", "b", "c"]
#end

it "uses the same order as keys() and values()" do
h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -27,4 +27,4 @@
keys.should == h.keys
values.should == h.values
end
end
end
20 changes: 13 additions & 7 deletions spec/rubyspec/core/hash/each_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
describe "Hash#each" do
it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do
all_args = []
{1 => 2, 3 => 4}.each { |*args| all_args << args }
all_args.sort.should == [[[1, 2]], [[3, 4]]]
end

it "yields the key and value of each pair to a block expecting |key, value|" do
r = {}
h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -7,12 +13,12 @@
end

# FIXME: should be: h.each { |k,| ary << k }
it "yields the key only to a block expecting |key,|" do
ary = []
h = {"a" => 1, "b" => 2, "c" => 3}
h.each { |k| ary << k }
ary.should == ["a", "b", "c"]
end
#it "yields the key only to a block expecting |key,|" do
# ary = []
# h = {"a" => 1, "b" => 2, "c" => 3}
# h.each { |k| ary << k }
# ary.should == ["a", "b", "c"]
#end

it "uses the same order as keys() and values()" do
h = {:a => 1, :b => 2, :c => 3, :d => 5}
@@ -27,4 +33,4 @@
keys.should == h.keys
values.should == h.values
end
end
end

0 comments on commit 361174d

Please sign in to comment.