
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
