Sha256: 0887b7fb647350c68960cdfc555e6fcb95b1a4c2c1b4fc21949ae0a0eb4aabfa
Contents?: true
Size: 745 Bytes
Versions: 2
Compression:
Stored size: 745 Bytes
Contents
module Hanoi module Jane class Dropper < Array def initialize stack, item stack.map { |i| self.push i } @item = item end def drop pos = Dropper.position self, @item self[pos] = @item unless pos >= self.length - 1 self[pos + 1] = nil end end def dropped (self[(Dropper.position self, @item) - 1] || self[(Dropper.position self, @item)]) || (Dropper.position self, @item) == 0 end def each until dropped drop yield self end end def Dropper.position stack, item pos = stack.index item return stack.length - 1 unless pos pos - 1 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hanoi-jane-0.3.1 | lib/hanoi/jane/animation/dropper.rb |
hanoi-jane-0.3.0 | lib/hanoi/jane/animation/dropper.rb |