class IRB::EvalHistory


# => 10
__[1]

# 3 nil
# 2 3
# => 1 10
__
# Inspect history (format is “<item number> <evaluated value>”:
# …error raised
raise RuntimeError
# => nil
# x
puts ‘x’
# => 3
1 + 2
# Perform some commands…
# => 10
IRB::CurrentContext().eval_history = 10
# Initialize history
Example (in ‘irb`):
(by default it is nil).
or IRB::CurrentContext().eval_history is non-nil integer value
Available via __ variable, only if IRB.conf[:EVAL_HISTORY]
Represents history of results of previously evaluated commands.

def [](idx)

Get one item of the content (both positive and negative indexes work).
def [](idx)
  begin
    if idx >= 0
      @contents.find{|no, val| no == idx}[1]
    else
      @contents[idx][1]
    end
  rescue NameError
    nil
  end
end

def initialize(size = 16) # :nodoc:

:nodoc:
def initialize(size = 16)  # :nodoc:
  @size = size
  @contents = []
end

def inspect # :nodoc:

:nodoc:
def inspect  # :nodoc:
  if @contents.empty?
    return real_inspect
  end
  unless (last = @contents.pop)[1].equal?(self)
    @contents.push last
    last = nil
  end
  str = @contents.collect{|no, val|
    if val.equal?(self)
      "#{no} ...self-history..."
    else
      "#{no} #{val.inspect}"
    end
  }.join("\n")
  if str == ""
    str = "Empty."
  end
  @contents.push last if last
  str
end

def push(no, val) # :nodoc:

:nodoc:
def push(no, val)  # :nodoc:
  @contents.push [no, val]
  @contents.shift if @size != 0 && @contents.size > @size
end

def size(size) # :nodoc:

:nodoc:
def size(size) # :nodoc:
  if size != 0 && size < @size
    @contents = @contents[@size - size .. @size]
  end
  @size = size
end