Sha256: f5d9552021aed945210e592f36178d8b1be8d0b909199a30a36dab3b2c24b5f6

Contents?: true

Size: 524 Bytes

Versions: 10

Compression:

Stored size: 524 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(&yld)
    a = []; self.times{ |i| a << yld.call(i) }
    a
  end

end


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

  require 'test/unit'

  class TCInteger < Test::Unit::TestCase

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

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-1.7.0 lib/facets/core/integer/of.rb
facets-1.7.30 lib/facets/core/integer/of.rb
facets-1.7.38 lib/facets/core/integer/of.rb
facets-1.7.46 lib/facets/core/integer/of.rb
facets-1.8.49 lib/facets/core/integer/of.rb
facets-1.8.0 lib/facets/core/integer/of.rb
facets-1.8.20 lib/facets/core/integer/of.rb
facets-1.8.51 lib/facets/core/integer/of.rb
facets-1.8.54 lib/facets/core/integer/of.rb
facets-1.8.8 lib/facets/core/integer/of.rb