Sha256: e2181cd549ae0ef6b7454d1cc2de4804454309cfad9e18115beeb970879681fa

Contents?: true

Size: 794 Bytes

Versions: 28

Compression:

Stored size: 794 Bytes

Contents

describe "Hash#each_pair" 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_pair { |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_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}
    keys = []
    values = []

    h.each_pair 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

Version Path
opal-0.4.3 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.4.2 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.4.1 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.4.0 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.3.44 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.3.43 spec/rubyspec/core/hash/each_pair_spec.rb
opal-0.3.42 spec/core/hash/each_pair_spec.rb
opal-0.3.41 spec/core/hash/each_pair_spec.rb
opal-0.3.40 spec/core/hash/each_pair_spec.rb
opal-0.3.39 spec/core/hash/each_pair_spec.rb
opal-0.3.38 spec/core/hash/each_pair_spec.rb
opal-0.3.37 spec/core/hash/each_pair_spec.rb
opal-0.3.36 spec/core/hash/each_pair_spec.rb
opal-0.3.35 spec/core/hash/each_pair_spec.rb
opal-0.3.34 spec/core/hash/each_pair_spec.rb
opal-0.3.33 spec/core/hash/each_pair_spec.rb
opal-0.3.32 spec/core/hash/each_pair_spec.rb
opal-0.3.31 spec/core/hash/each_pair_spec.rb
opal-0.3.30 spec/core/hash/each_pair_spec.rb
opal-0.3.29 spec/core/hash/each_pair_spec.rb