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