Sha256: b336d0c5a423b5d6c1fddb5b1d92701ad886287a9820c40a5a7c00fc76080bb6

Contents?: true

Size: 480 Bytes

Versions: 1

Compression:

Stored size: 480 Bytes

Contents

class ImmutableStack
  def pop()
    [@head, @tail]
  end

  def push(element)
    ImmutableStack.new(element, self)
  end

  def self.empty()
    @@empty ||= self.new(nil, nil)
  end

  def each()
    yield(head)
    t = tail
    while t.!=(ImmutableStack.empty) do
      h, t = t.pop
      yield(h)
    end
  end

  def initialize(h, t)
    @head = h
    @tail = t
    self.freeze
  end

  private


  attr_reader :head
  attr_reader :tail

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maroon-0.7.1 lib/ImmutableStack.rb