Class: PrettyPrint::GroupQueue
Instance Method Summary collapse
- #delete(group) ⇒ Object
- #deq ⇒ Object
- #enq(group) ⇒ Object
-
#initialize(*groups) ⇒ GroupQueue
constructor
A new instance of GroupQueue.
Constructor Details
#initialize(*groups) ⇒ GroupQueue
Returns a new instance of GroupQueue.
311 312 313 314 |
# File 'lib/project/prettyprint.rb', line 311 def initialize(*groups) @queue = [] groups.each {|g| enq g} end |
Instance Method Details
#delete(group) ⇒ Object
337 338 339 |
# File 'lib/project/prettyprint.rb', line 337 def delete(group) @queue[group.depth].delete(group) end |
#deq ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/project/prettyprint.rb', line 322 def deq @queue.each {|gs| (gs.length-1).downto(0) {|i| unless gs[i].breakables.empty? group = gs.slice!(i, 1).first group.break return group end } gs.each {|group| group.break} gs.clear } return nil end |
#enq(group) ⇒ Object
316 317 318 319 320 |
# File 'lib/project/prettyprint.rb', line 316 def enq(group) depth = group.depth @queue << [] until depth < @queue.length @queue[depth] << group end |