class IRB::History

Represents history of results of previously evaluated commands.

Available via __ variable, only if IRB.conf[:EVAL_HISTORY] or IRB::CurrentContext().eval_history is non-nil integer value (by default it is nil).

Example (in ‘irb`):

# Initialize history
IRB::CurrentContext().eval_history = 10
# => 10

# Perform some commands...
1 + 2
# => 3
puts 'x'
# x
# => nil
raise RuntimeError
# ...error raised

# Inspect history (format is "<item number> <evaluated value>":
__
# => 1 10
# 2 3
# 3 nil

__[1]
# => 10

Public Instance Methods

[](idx) click to toggle source

Get one item of the content (both positive and negative indexes work).

# File lib/irb/ext/history.rb, line 113
def [](idx)
  begin
    if idx >= 0
      @contents.find{|no, val| no == idx}[1]
    else
      @contents[idx][1]
    end
  rescue NameError
    nil
  end
end