base/ImmutableStack.rb in maroon-0.6.5 vs base/ImmutableStack.rb in maroon-0.7.0
- old
+ new
@@ -1,30 +1,32 @@
context :ImmutableStack do
role :head do
end
role :tail do
end
- pop do
+
+ def pop
[@head, @tail]
end
- push do |element|
+
+ def push(element)
ImmutableStack.new element, self
end
- empty self do
+ def self.empty
@@empty ||= self.new(nil, nil)
end
- each do
+ def each
yield head
t = tail
while t != ImmutableStack::empty do
h, t = t.pop
yield h
end
end
- initialize do |h, t|
+ def initialize(h, t)
@head = h
@tail = t
self.freeze
end
end