Sha256: 6818fade0966de6e6650d5bad1bd492205f66e0d38bef7dd417555f5a63e5c9e

Contents?: true

Size: 656 Bytes

Versions: 6

Compression:

Stored size: 656 Bytes

Contents

describe "Array#collect" do
  it "returns a copy of array with each element replaced by the value returned by block" do
    a = ['a', 'b', 'c', 'd']
    b = a.collect { |i| i + '!'}
    b.should == ['a!', 'b!', 'c!', 'd!']
    # a.object_id.should_not == a.object_id
  end
  
  it "does not change self" do
    a = ['a', 'b', 'c', 'd']
    b = a.collect { |i| i + '!' }
    a.should == ['a', 'b', 'c', 'd']
  end
  
  it "returns the evaluated value of the block 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
  end  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-0.3.2 gems/core/spec/core/array/collect_spec.rb
opal-0.3.1 gems/core/spec/core/array/collect_spec.rb
opal-0.3.0 gems/core/spec/core/array/collect_spec.rb
opal-0.2.2 opals/opal/opal/spec/core/array/collect_spec.rb
opal-0.2.0 opals/opal/opal/spec/core/array/collect_spec.rb
opal-0.1.0 opals/opal/spec/core/array/collect_spec.rb