Sha256: e92e268bdba0368b64ba648d8bf1539972e8d3bfeced90029f9358ae3a0e3440

Contents?: true

Size: 568 Bytes

Versions: 1

Compression:

Stored size: 568 Bytes

Contents

class Integer

  # Like #times but returns a collection of the yield results.
  #
  #   a = 3.times_collect { |i| "#{i+1}" }
  #   a => [ "1", "2", "3" ]
  #
  def times_collect(&yld)
    a = []; self.times{ |i| a << yld.call(i) }
    a
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCInteger < Test::Unit::TestCase

    def test_times_collect
      a = 4
      b = a.times_collect{ |i| i*2 }
      assert_equal( [0,2,4,6], b )
    end

  end

=end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/integer/times_collect.rb