Sha256: 4fb19afed84bb71c1c4da75817a9bd934b2e4da47b98128d55fcbf51ad7f9909

Contents?: true

Size: 611 Bytes

Versions: 25

Compression:

Stored size: 611 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

  alias_method :times_map, :times_collect

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

25 entries across 25 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/integer/times_collect.rb
facets-1.0.3 packages/core/lib/facet/integer/times_collect.rb
facets-1.3.0 lib/facets/core/integer/times_collect.rb
facets-1.1.0 lib/facet/integer/times_collect.rb
facets-1.2.0 lib/facets/core/integer/times_collect.rb
facets-1.2.1 lib/facets/core/integer/times_collect.rb
facets-1.3.2 lib/facets/core/integer/times_collect.rb
facets-1.3.1 lib/facets/core/integer/times_collect.rb
facets-1.3.3 lib/facets/core/integer/times_collect.rb
facets-1.4.2 lib/facets/core/integer/times_collect.rb
facets-1.4.0 lib/facets/core/integer/times_collect.rb
facets-1.4.1 lib/facets/core/integer/times_collect.rb
facets-1.4.3 lib/facets/core/integer/times_collect.rb
facets-1.4.4 lib/facets/core/integer/times_collect.rb
facets-1.4.5 lib/facets/core/integer/times_collect.rb
facets-1.7.38 lib/facets/core/integer/times_collect.rb
facets-1.7.0 lib/facets/core/integer/times_collect.rb
facets-1.7.30 lib/facets/core/integer/times_collect.rb
facets-1.7.46 lib/facets/core/integer/times_collect.rb
facets-1.8.0 lib/facets/core/integer/times_collect.rb