class Deflating
Array where the elements that can't be shrunk are removed
Public Class Methods
new(a)
click to toggle source
# File lib/rantly/shrinks.rb, line 113 def initialize(a) @array = a @position = a.size - 1 end
Public Instance Methods
[](i)
click to toggle source
# File lib/rantly/shrinks.rb, line 118 def [](i) @array[i] end
[]=(i, value)
click to toggle source
# File lib/rantly/shrinks.rb, line 122 def []=(i, value) @array[i] = value end
array()
click to toggle source
# File lib/rantly/shrinks.rb, line 146 def array return @array end
each(&block)
click to toggle source
# File lib/rantly/shrinks.rb, line 142 def each(&block) @array.each(&block) end
inspect()
click to toggle source
# File lib/rantly/shrinks.rb, line 138 def inspect self.to_s end
length()
click to toggle source
# File lib/rantly/shrinks.rb, line 126 def length @array.length end
retry?()
click to toggle source
# File lib/rantly/shrinks.rb, line 164 def retry? @position >= 0 end
shrink()
click to toggle source
# File lib/rantly/shrinks.rb, line 150 def shrink shrunk = @array.dup if @position >= 0 e = @array.at(@position) if e.respond_to?(:shrinkable?) && e.shrinkable? shrunk[@position] = e.shrink else shrunk.delete_at(@position) end @position -= 1 end return Deflating.new(shrunk) end
shrinkable?()
click to toggle source
# File lib/rantly/shrinks.rb, line 168 def shrinkable? !@array.empty? end
size()
click to toggle source
# File lib/rantly/shrinks.rb, line 130 def size self.length end
to_s()
click to toggle source
# File lib/rantly/shrinks.rb, line 134 def to_s @array.to_s.insert(1, "D ") end