Sha256: 0616e76adb924133c39b802e09bd8a7719be704aef773494c5a6031e596d8b66

Contents?: true

Size: 518 Bytes

Versions: 29

Compression:

Stored size: 518 Bytes

Contents

describe "Hash#keep_if" do
  it "yields two arguments: key and value" do
    all_args = []
    {1 => 2, 3 => 4}.keep_if { |*args| all_args << args }
    all_args.should == [[1, 2], [3, 4]]
  end

  it "keeps every entry for which block is true and returns self" do
    h = {:a => 1, :b => 2, :c => 3, :d => 4}
    h.keep_if { |k,v| v % 2 == 0 }.should equal(h)
    h.should == {:b => 2, :d => 4}
  end

  it "returns self even if unmodified" do
    h = {1 => 2, 3 => 4}
    h.keep_if { true }.should equal(h)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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