lib/ImmutableStack.rb in maroon-0.7.1 vs lib/ImmutableStack.rb in maroon-0.8.0

- old
+ new

@@ -1,35 +1,21 @@ class ImmutableStack - def pop() - [@head, @tail] - end + 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 - def push(element) - ImmutableStack.new(element, self) - end - def self.empty() - @@empty ||= self.new(nil, nil) - end +attr_reader :head, :tail - 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 + end \ No newline at end of file