Sha256: 0b1dbe4bc808d711f65404ff60b8661122de597970f7bb7c498bea538340660b

Contents?: true

Size: 813 Bytes

Versions: 9

Compression:

Stored size: 813 Bytes

Contents

#
class Integer

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

  #def of(&yld)
  #  a = []; self.times{ |i| a << yld.call(i) }
  #  a
  #end

  # Time warn aliases for #of.
  alias_method :times_collect, :of
  alias_method :times_map, :of

end




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

  require 'test/unit'

  class TestIntegerEnumerate < Test::Unit::TestCase

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

    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

9 entries across 9 versions & 1 rubygems

Version Path
facets-2.0.1 lib/core/facets/integer/of.rb
facets-2.0.2 lib/core/facets/integer/of.rb
facets-2.0.3 lib/core/facets/integer/of.rb
facets-2.0.4 lib/core/facets/integer/of.rb
facets-2.1.1 lib/core/facets/integer/of.rb
facets-2.1.2 lib/core/facets/integer/of.rb
facets-2.1.0 lib/core/facets/integer/of.rb
facets-2.0.5 lib/core/facets/integer/of.rb
facets-2.1.3 lib/core/facets/integer/of.rb