Sha256: d1f3db492776f4d647d984a5a706725e6e89ca63b564f2eb2aecb199ba1f2528

Contents?: true

Size: 658 Bytes

Versions: 10

Compression:

Stored size: 658 Bytes

Contents

class Array

  # Alias for shift which removes an object off first slot of an array.
  # This is the opposite of pop.
  alias_method :pull, :shift

  # Peek at the top of the stack (the end of the array).
  #
  #   a = [1, 2, 3]
  #   a.peek          #=> 3
  #   a               #=> [1, 2, 3]
  #
  # Or provide an index to inspect the array from back to front.
  def peek(i=0)
    i = -(i + 1)
    fetch(i)
  end

  # Put an object on the bottom of the stack (front of the array).
  #
  #   a = [2, 3]
  #   a.poke(1)
  #   a               #=> [1, 2, 3]
  #
  # Or supply an index and #poke works like #insert.
  def poke(x, i=0)
    insert(i,x)
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/array/pull.rb
facets-3.1.0 lib/core/facets/array/pull.rb
facets-3.0.0 lib/core/facets/array/pull.rb
facets-2.9.3 lib/core/facets/array/pull.rb
facets-2.9.2 lib/core/facets/array/pull.rb
facets-2.9.2 src/core/facets/array/pull.rb
facets-2.9.1 lib/core/facets/array/pull.rb
facets-2.9.0 lib/core/facets/array/pull.rb
facets-2.9.0.pre.2 lib/core/facets/array/pull.rb
facets-2.9.0.pre.1 lib/core/facets/array/pull.rb