base/immutable_queue.rb in maroon-0.6.5 vs base/immutable_queue.rb in maroon-0.7.0
- old
+ new
@@ -1,16 +1,17 @@
context :ImmutableQueue do
role :front do
end
role :back do
end
- push do |element|
+
+ def push(element)
b = back || ImmutableStack::empty
ImmutableQueue.new(front, b.push(element))
end
- pop do
+ def pop
f, b = front, back
if f == ImmutableStack::empty
#reverse the back stack to be able to pop from the front in correct order
until b == ImmutableStack::empty
e, b = b.pop
@@ -23,15 +24,15 @@
else
[head, ImmutableQueue.new(f, b)]
end
end
- empty true do
+ def self.empty
@@empty ||= ImmutableQueue.new(ImmutableStack::empty, ImmutableStack::empty)
end
- push_array do |arr|
+ def push_array(arr)
q = self
if arr
arr.each do |i|
q = q.push i
end
@@ -39,10 +40,10 @@
q
end
private
- initialize do |front, back|
+ def initialize(front, back)
@front = front || ImmutableStack::empty
@back = back || ImmutableStack::empty
self.freeze
end
\ No newline at end of file