class Reline::History

def <<(val)

def <<(val)
  # If history_size is zero, all histories are dropped.
  return self if @config.history_size.zero?
  # If history_size is negative, history size is unlimited.
  if @config.history_size.positive?
    shift if size + 1 > @config.history_size
  end
  super(String.new(val, encoding: Reline.encoding_system_needs))
end

def [](index)

def [](index)
  index = check_index(index) unless index.is_a?(Range)
  super(index)
end

def []=(index, val)

def []=(index, val)
  index = check_index(index)
  super(index, String.new(val, encoding: Reline.encoding_system_needs))
end

def check_index(index)

def check_index(index)
+= size if index < 0
ex < -2147483648 or 2147483647 < index
e RangeError.new("integer #{index} too big to convert to `int'")
istory_size is negative, history size is unlimited.
nfig.history_size.positive?
ndex < -@config.history_size or @config.history_size < index
ise RangeError.new("index=<#{index}>")
IndexError.new("index=<#{index}>") if index < 0 or size <= index

def concat(*val)

def concat(*val)
  val.each do |v|
    push(*v)
  end
end

def delete_at(index)

def delete_at(index)
  index = check_index(index)
  super(index)
end

def initialize(config)

def initialize(config)
  @config = config
end

def push(*val)

def push(*val)
  # If history_size is zero, all histories are dropped.
  return self if @config.history_size.zero?
  # If history_size is negative, history size is unlimited.
  if @config.history_size.positive?
    diff = size + val.size - @config.history_size
    if diff > 0
      if diff <= size
        shift(diff)
      else
        diff -= size
        clear
        val.shift(diff)
      end
    end
  end
  super(*(val.map{ |v|
    String.new(v, encoding: Reline.encoding_system_needs)
  }))
end

def to_s

def to_s
  'HISTORY'
end