Sha256: 65e27c5ce30ba5d2c216543fbb53a29c4c1d55947647f695a87ee9f94dfbb058
Contents?: true
Size: 774 Bytes
Versions: 28
Compression:
Stored size: 774 Bytes
Contents
describe "Hash#each" do 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} h.each { |k,v| r[k.to_s] = v.to_s }.should equal(h) r.should == {"a" => "1", "b" => "2", "c" => "3", "d" => "5"} 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 "uses the same order as keys() and values()" do h = {:a => 1, :b => 2, :c => 3, :d => 5} keys = [] values = [] h.each do |k, v| keys << k values << v end keys.should == h.keys values.should == h.values end end
Version data entries
28 entries across 28 versions & 1 rubygems