Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus