Sha256: 71f891e2d7cf33985ee4c8a5be7afd34d1f1bf341c775b8948dc70b934d4cce2

Contents?: true

Size: 357 Bytes

Versions: 4

Compression:

Stored size: 357 Bytes

Contents

# Extend core Array by adding {to_proc} which will enable arrays to be treated as functions
# of their indexes.
class Array
  # Return a proc that takes the index of the array and returns the value at that index or nil
  # if there is no value at the given index.
  #
  # @return [Proc]
  def to_proc
    lambda do |index|
      at(index)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
invokable-1.0.0 lib/invokable/array.rb
invokable-0.7.2 lib/invokable/array.rb
invokable-0.7.1 lib/invokable/array.rb
invokable-0.7.0 lib/invokable/array.rb