Sha256: e12ffcb97edee64cc2447864c10a4fd8acd6dff621e32516b8446ed63cb985f5

Contents?: true

Size: 683 Bytes

Versions: 3

Compression:

Stored size: 683 Bytes

Contents

class Stack {
  """
  A simple Stack container class.
  """

  def initialize {
    @arr = []
  }

  def initialize: size {
    "Initializes a new Stack with a given size."

    @arr = Array new: size
  }

  def push: obj {
    "Pushes a value onto the Stack."

    @arr << obj
  }

  def << obj {
    "Same as Stack#push:."

    @arr << obj
  }

  def pop {
    "Pops the top-of-stack element from the Stack and returns it."

    @arr remove_at: (size - 1)
  }

  def top {
    "Returns the top-of-stack element."

    @arr last
  }

  def size {
    "Returns the size of the Stack."

    @arr size
  }

  def empty? {
    "Indicates, if the Stack is empty."

    @arr empty?
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fancy-0.3.3 lib/stack.fy
fancy-0.3.2 lib/stack.fy
fancy-0.3.1 lib/stack.fy