Sha256: a3ac3d837fef0c1084bc713ab6761a812d10f5f77a056e87f0f7613726e2c247

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

# TITLE:
#   Stackable
#
# DESCRIPTION:
#   Array extensions for stack maniipulation.
#
# NOTES:
#   - TODO Better name than #place --top, put, or what?

require 'facets/array/splice'
require 'facets/stackable'

class Array
  include Stackable

  # "Put On Top". This is an alias for unshift
  # which puts an object# on top of the stack.
  # It is the converse of push.
  #
  #  a=[1,2,3]
  #  a.place(9)   #=> [9,1,2,3]
  #  a          #=> [9,1,2,3]
  #
  alias_method :poke, :unshift

  # Alias for shift which removes an object
  # off first slot of an array. This is
  # the contrary of pop.
  #
  #   a=[1,2,3]
  #   a.pull  #=> 1
  #   a       #=> [2,3]
  #
  alias_method :pull, :shift
end


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

  require 'test/unit'

  class TestArray < Test::Unit::TestCase

    def test_poke
      a = [2,3]
      assert_equal( [1,2,3], a.poke(1) )
      assert_equal( [4,1,2,3], a.poke(4) )
    end

    def test_pull
      a = [1,2,3]
      assert_equal( 1, a.pull )
      assert_equal( [2,3], a )
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.0.1 lib/core/facets/array/stackable.rb
facets-2.0.0 lib/core/facets/array/stackable.rb
facets-2.0.2 lib/core/facets/array/stackable.rb
facets-2.0.4 lib/core/facets/array/stackable.rb
facets-2.0.5 lib/core/facets/array/stackable.rb
facets-2.1.1 lib/core/facets/array/stackable.rb
facets-2.1.2 lib/core/facets/array/stackable.rb
facets-2.1.0 lib/core/facets/array/stackable.rb
facets-2.0.3 lib/core/facets/array/stackable.rb
facets-2.1.3 lib/core/facets/array/stackable.rb