Sha256: edb48ac74598a523376a24f9690060af911938fe14627368c55e3c7db3b9ede6
Contents?: true
Size: 707 Bytes
Versions: 22
Compression:
Stored size: 707 Bytes
Contents
describe "Array#reduce" do it "returns a single value and accepts the default value" do a = (1..7) b = a.reduce(1) { |sum, i| sum + i } b.should == 29 end it "also responds to #inject and works with no default value" do a = (12..15) b = a.reduce { |sum, i| sum + i } b.should == 54 end it "does not change self" do a = ['a', 'b', 'c', 'd'] b = a.reduce('e') { |sum, i| [sum, i].join } a.should == ['a', 'b', 'c', 'd'] end it "returns the evaluated value of block if it broke in the block" do a = ['a', 'b', 'c', 'd'] b = a.reduce { |sum, i| if i == 'c' break 9 else i + '!' end } b.should == 9 end end
Version data entries
22 entries across 22 versions & 1 rubygems