class HanoiTower::Tower
Attributes
rings[R]
Public Class Methods
new(ring_size)
click to toggle source
# File lib/hanoi_tower/tower.rb, line 5 def initialize(ring_size) @rings = ring_size.times.reverse_each.map {|v| Ring.new(v + 1) } end
Public Instance Methods
can_push?(ring)
click to toggle source
# File lib/hanoi_tower/tower.rb, line 9 def can_push?(ring) if @rings.last.nil? true else @rings.last.can_push?(ring) end end
pop()
click to toggle source
# File lib/hanoi_tower/tower.rb, line 21 def pop @rings.pop end
push(ring)
click to toggle source
# File lib/hanoi_tower/tower.rb, line 17 def push ring @rings << ring end
to_s()
click to toggle source
# File lib/hanoi_tower/tower.rb, line 25 def to_s @rings.map(&:to_s).join('-') end