The History class is responsible for maintaining the user's input history, both internally and within Readline.
Clear all history. Anything the user entered before this point won't be saved, but anything they put in afterwards will still be appended to the history file on exit.
# File lib/pry/history.rb, line 55 def clear @clearer.call @history = [] @saved_lines = 0 end
Load the input history using `History.loader`. @return [Integer] The number of lines loaded
# File lib/pry/history.rb, line 23 def load @loader.call do |line| @pusher.call(line.chomp) @history << line.chomp end @saved_lines = @history.length end
Add a line to the input history, ignoring blank and duplicate lines. @param [String] line @return [String] The same line that was passed in
# File lib/pry/history.rb, line 43 def push(line) unless line.empty? || (@history.last && line == @history.last) @pusher.call(line) @history << line end line end
Assign the default methods for loading, saving, pushing, and clearing.
# File lib/pry/history.rb, line 14 def restore_default_behavior @loader = method(:read_from_file) @saver = method(:write_to_file) @pusher = method(:push_to_readline) @clearer = method(:clear_readline) end
Write this session's history using `History.saver`. @return [Integer] The number of lines saved
# File lib/pry/history.rb, line 33 def save history_to_save = @history[@saved_lines..-1] @saver.call(history_to_save) @saved_lines = @history.length history_to_save.length end
Generated with the Darkfish Rdoc Generator 2.