Class: IRB::History (Ruby 2.7.5)
Description: Class : IRB::History - Ruby 2.7.5

### Home Classes Methods

### In Files

- irb/ext/history.rb

### Parent

Object

### Methods

- #[]

### Class/Module Index

Quicksearch

- Binding
- IRB::Abort
- IRB::Canvas
- IRB::Color
- IRB::Color::SymbolState
- IRB::Context
- IRB::ContextExtender
- IRB::ExtendCommandBundle
- IRB::FileInputMethod
- IRB::Frame
- IRB::Frame::FrameOverflow
- IRB::Frame::FrameUnderflow
- IRB::History
- IRB::InputMethod
- IRB::Inspector
- IRB::Irb
- IRB::IrbLoader
- IRB::JobManager
- IRB::LoadAbort
- IRB::MethodExtender
- IRB::Notifier
- IRB::Notifier::AbstractNotifier
- IRB::Notifier::CompositeNotifier
- IRB::Notifier::ErrUndefinedNotifier
- IRB::Notifier::ErrUnrecognizedLevel
- IRB::Notifier::LeveledNotifier
- IRB::Notifier::NoMsgNotifier
- IRB::OutputMethod
- IRB::OutputMethod::NotImplementedError
- IRB::ReadlineInputMethod
- IRB::ReidlineInputMethod
- IRB::RubyModel
- IRB::StdioInputMethod
- IRB::StdioOutputMethod
- IRB::Vec
- IRB::WorkSpace
- Object
- XMP
- XMP::StringInputMethod

No matching classes.

# 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 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