123456789_123456789_123456789_123456789_123456789_

Class: IRB::Command::History

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base
Inherits: IRB::Command::Base
Defined in: lib/irb/command/history.rb

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Constructor Details

This class inherits a constructor from IRB::Command::Base

Instance Method Details

#execute(arg)

[ GitHub ]

  
# File 'lib/irb/command/history.rb', line 15

def execute(arg)

  if (match = arg&.match(/(-g|-G)\s(?<grep>.)\s*\n\z/))
    grep = Regexp.new(match[:grep])
  end

  formatted_inputs = irb_context.io.class::HISTORY.each_with_index.reverse_each.filter_map do |input, index|
    next if grep && !input.match?(grep)

    header = "#{index}: "

    first_line, *other_lines = input.split("\n")
    first_line = "#{header}#{first_line}"

    truncated_lines = other_lines.slice!(1..) # Show 1 additional line (2 total)
    other_lines << "..." if truncated_lines&.any?

    other_lines.map! do |line|
      " " * header.length + line
    end

    [first_line, *other_lines].join("\n") + "\n"
  end

  Pager.page_content(formatted_inputs.join)
end