class GrnLine::History
Attributes
lines[R]
Public Class Methods
new(file)
click to toggle source
# File lib/grnline/history.rb, line 6 def initialize(file) @history_file = file @lines = [] end
Public Instance Methods
load()
click to toggle source
# File lib/grnline/history.rb, line 11 def load @lines = read Readline::HISTORY.push(*@lines) end
save()
click to toggle source
# File lib/grnline/history.rb, line 16 def save saved_history = read return if saved_history == @lines new_history = (@lines + saved_history).uniq File.open(@history_file, "w") do |file| file.print(new_history.join("\n")) end end
store(line)
click to toggle source
# File lib/grnline/history.rb, line 27 def store(line) @lines << line end
Private Instance Methods
read()
click to toggle source
# File lib/grnline/history.rb, line 33 def read return [] unless File.exist?(@history_file) File.readlines(@history_file).collect {|line| line.chomp} end