In Files

  • irb/ext/history.rb

IRB::History

Public Class Methods

new(size = 16) click to toggle source
 
               # File irb/ext/history.rb, line 53
def initialize(size = 16)
  @size = size
  @contents = []
end
            

Public Instance Methods

[](idx) click to toggle source
 
               # File irb/ext/history.rb, line 65
def [](idx)
  begin
    if idx >= 0
      @contents.find{|no, val| no == idx}[1]
    else
      @contents[idx][1]
    end
  rescue NameError
    nil
  end
end
            
inspect() click to toggle source
 
               # File irb/ext/history.rb, line 84
def inspect
  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
            
Also aliased as: real_inspect
push(no, val) click to toggle source
 
               # File irb/ext/history.rb, line 77
def push(no, val)
  @contents.push [no, val]
  @contents.shift if @size != 0 && @contents.size > @size
end
            
real_inspect() click to toggle source
Alias for: inspect
size(size) click to toggle source
 
               # File irb/ext/history.rb, line 58
def size(size)
  if size != 0 && size < @size
    @contents = @contents[@size - size .. @size]
  end
  @size = size
end