Sha256: e9bb74ccc1fd5a7763b23471e9715a0d6129482b79e9bb7ada7d2f05f25d2bfe
Contents?: true
Size: 623 Bytes
Versions: 6
Compression:
Stored size: 623 Bytes
Contents
describe "Array#collect!" do it "replaces each element with the value returned by block" do a = [7, 9, 3, 5] a.collect! { |i| i - 1 } a.should == [6, 8, 2, 4] end it "returns self" do a = [1, 2, 3, 4, 5] b = a.collect! { |i| i + 1 } a.object_id.should == b.object_id end it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do a = ['a', 'b', 'c', 'd'] b = a.collect! do |i| if i == 'c' break 0 else i + '!' end end b.should == 0 a.should == ['a!', 'b!', 'c', 'd'] end end
Version data entries
6 entries across 6 versions & 1 rubygems