class Readline::HISTORY
The History class encapsulates a history of all commands entered by users at the prompt, providing an interface for inspection and retrieval of all commands.
Public Class Methods
Synonym for RbReadline#add_history.
# File lib/readline.rb, line 366 def self.<<(str) RbReadline.add_history(str) end
Returns the command that was entered at the specified index
in
the history buffer.
Raises an IndexError if the entry is nil.
# File lib/readline.rb, line 337 def self.[](index) if index < 0 index += RbReadline.history_length end entry = RbReadline.history_get(RbReadline.history_base+index) if entry.nil? raise IndexError,"invalid index" end entry.line.dup end
Sets the command str
at the given index in the history buffer.
You can only replace an existing entry. Attempting to create a new entry will result in an IndexError.
# File lib/readline.rb, line 353 def self.[]=(index,str) if index<0 index += RbReadline.history_length end entry = RbReadline.replace_history_entry(index,str,nil) if entry.nil? raise IndexError,"invalid index" end str end
Deletes an entry from the histoyr buffer at the specified
index
.
# File lib/readline.rb, line 445 def self.delete_at(index) if index < 0 i += RbReadline.history_length end if index < 0 || index > RbReadline.history_length - 1 raise IndexError, "invalid index" end rb_remove_history(index) end
Iterates over each entry in the history buffer.
# File lib/readline.rb, line 415 def self.each() for i in 0 ... RbReadline.history_length entry = RbReadline.history_get(RbReadline.history_base + i) break if entry.nil? yield entry.line.dup end self end
Returns a bolean value indicating whether or not the history buffer is empty.
# File lib/readline.rb, line 439 def self.empty?() RbReadline.history_length == 0 end
Returns the length of the history buffer.
# File lib/readline.rb, line 426 def self.length() RbReadline.history_length end
Removes and returns the last element from the history buffer.
# File lib/readline.rb, line 395 def self.pop() if RbReadline.history_length>0 rb_remove_history(RbReadline.history_length-1) else nil end end
Pushes a list of args
onto the history buffer.
# File lib/readline.rb, line 372 def self.push(*args) args.each do |str| RbReadline.add_history(str) end end
Internal function that removes the item at index
from the
history buffer, performing necessary duplication in the process.
# File lib/readline.rb, line 383 def self.rb_remove_history(index) entry = RbReadline.remove_history(index) if (entry) val = entry.line.dup entry = nil return val end nil end
Removes and returns the first element from the history buffer.
# File lib/readline.rb, line 405 def self.shift() if RbReadline.history_length>0 rb_remove_history(0) else nil end end
Synonym for Readline.length.
# File lib/readline.rb, line 432 def self.size() RbReadline.history_length end
The History class, stringified in all caps.
# File lib/readline.rb, line 328 def self.to_s "HISTORY" end