class Tuple
Array where elements can be shrunk but not removed
Attributes
array[R]
Public Class Methods
new(a)
click to toggle source
# File lib/rantly/shrinks.rb, line 49 def initialize(a) @array = a @position = a.size - 1 end
Public Instance Methods
[](i)
click to toggle source
# File lib/rantly/shrinks.rb, line 54 def [](i) @array[i] end
[]=(i, value)
click to toggle source
# File lib/rantly/shrinks.rb, line 58 def []=(i, value) @array[i] = value end
each(&block)
click to toggle source
# File lib/rantly/shrinks.rb, line 78 def each(&block) @array.each(&block) end
inspect()
click to toggle source
# File lib/rantly/shrinks.rb, line 74 def inspect to_s end
length()
click to toggle source
# File lib/rantly/shrinks.rb, line 62 def length @array.length end
retry?()
click to toggle source
# File lib/rantly/shrinks.rb, line 99 def retry? @position >= 0 end
shrink()
click to toggle source
# File lib/rantly/shrinks.rb, line 84 def shrink shrunk = @array.dup while @position >= 0 e = @array.at(@position) break if e.respond_to?(:shrinkable?) && e.shrinkable? @position -= 1 end if @position >= 0 shrunk[@position] = e.shrink @position -= 1 end Tuple.new(shrunk) end
shrinkable?()
click to toggle source
# File lib/rantly/shrinks.rb, line 103 def shrinkable? @array.any? { |e| e.respond_to?(:shrinkable?) && e.shrinkable? } end
size()
click to toggle source
# File lib/rantly/shrinks.rb, line 66 def size length end
to_s()
click to toggle source
# File lib/rantly/shrinks.rb, line 70 def to_s @array.to_s.insert(1, 'T ') end