class Deflating

Array where the elements that can't be shrunk are removed

Attributes

array[R]

Public Class Methods

new(a) click to toggle source
# File lib/rantly/shrinks.rb, line 110
def initialize(a)
  @array = a
  @position = a.size - 1
end

Public Instance Methods

[](i) click to toggle source
# File lib/rantly/shrinks.rb, line 115
def [](i)
  @array[i]
end
[]=(i, value) click to toggle source
# File lib/rantly/shrinks.rb, line 119
def []=(i, value)
  @array[i] = value
end
each(&block) click to toggle source
# File lib/rantly/shrinks.rb, line 139
def each(&block)
  @array.each(&block)
end
inspect() click to toggle source
# File lib/rantly/shrinks.rb, line 135
def inspect
  to_s
end
length() click to toggle source
# File lib/rantly/shrinks.rb, line 123
def length
  @array.length
end
retry?() click to toggle source
# File lib/rantly/shrinks.rb, line 159
def retry?
  @position >= 0
end
shrink() click to toggle source
# File lib/rantly/shrinks.rb, line 145
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
  Deflating.new(shrunk)
end
shrinkable?() click to toggle source
# File lib/rantly/shrinks.rb, line 163
def shrinkable?
  !@array.empty?
end
size() click to toggle source
# File lib/rantly/shrinks.rb, line 127
def size
  length
end
to_s() click to toggle source
# File lib/rantly/shrinks.rb, line 131
def to_s
  @array.to_s.insert(1, 'D ')
end