class Pry::HistoryArray

ary # => 9<br>ary # => nil
10.times { |n| ary << n }
# => 2<br>ary # => 1
ary << 1 << 2 << 3
ary = Pry::HistoryArray.new 10
@example
History arrays are used by Pry to store the output of the last commands.
N elements.
entries are removed progressively, so that the aray never contains more than
A history array is an array to which you can only add elements. Older

def <<(value)

Parameters:
  • value (Object) -- Object to be added
def <<(value)
  @hash[@count] = value
  if @hash.size > max_size
    @hash.delete(@count - max_size)
  end
  @count += 1
  self
end

def [](index_or_range, size = nil)

Returns:
  • (Array, nil) - The selected items. Nil if index is greater than
  • (Array, nil) - The selected items. Nil if index is greater than
  • (Object, nil) - Item at that index or nil if it has been removed.

Parameters:
  • range (Range) -- Range of indices to access.
  • size (Integer) -- Amount of items to access
  • index (Integer) -- Index of the first item to access.
  • index (Integer) -- Index of the item to access.

Overloads:
  • [](range)
  • [](index, size)
  • [](index)
def [](index_or_range, size = nil)
  if index_or_range.is_a? Integer
    index = convert_index(index_or_range)
    if size
      end_index = index + size
      index > @count ? nil : (index...[end_index, @count].min).map do |n|
        @hash[n]
      end
    else
      @hash[index]
    end
  else
    range = convert_range(index_or_range)
    range.begin > @count ? nil : range.map { |n| @hash[n] }
  end
end

def convert_index(n)

def convert_index(n)
  n >= 0 ? n : @count + n
end

def convert_range(range)

def convert_range(range)
  end_index = convert_index(range.end)
  end_index += 1 unless range.exclude_end?
  Range.new(convert_index(range.begin), [end_index, @count].min, true)
end

def each

def each
  ((@count - size)...@count).each do |n|
    yield @hash[n]
  end
end

def empty?

def empty?
  size == 0
end

def initialize(size)

Parameters:
  • size (Integer) -- Maximum amount of objects in the array
def initialize(size)
  @max_size = size
  @hash  = {}
  @count = 0
end

def inspect

def inspect
  "#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
end

def pop!

def pop!
  @hash.delete @count - 1
  @count -= 1
end

def size

Returns:
  • (Integer) - Amount of objects in the array
def size
  @count
end

def to_a

def to_a
  ((@count - size)...@count).map { |n| @hash[n] }
end