Module: Ripl::History

Included in:
Shell
Defined in:
lib/ripl/history.rb

Constant Summary collapse

HISTORY_FILE =
'~/.irb_history'

Instance Method Summary collapse

Instance Method Details

#after_loopObject



26
# File 'lib/ripl/history.rb', line 26

def after_loop() super; write_history end

#before_loopObject



25
# File 'lib/ripl/history.rb', line 25

def before_loop() super; read_history end

#get_inputObject



10
11
12
# File 'lib/ripl/history.rb', line 10

def get_input
  (history << super)[-1]
end

#historyObject



8
# File 'lib/ripl/history.rb', line 8

def history() @history ||= [] end

#history_fileObject



4
5
6
# File 'lib/ripl/history.rb', line 4

def history_file
  @history_file ||= config[:history] && File.expand_path(config[:history])
end

#read_historyObject



14
15
16
17
18
# File 'lib/ripl/history.rb', line 14

def read_history
  if ((history_file && File.exists?(history_file)) && history.empty?)
    IO.readlines(history_file).each {|e| history << e.chomp }
  end
end

#write_historyObject



20
21
22
23
24
# File 'lib/ripl/history.rb', line 20

def write_history
  if history_file
    File.open(history_file, 'w') {|f| f.puts(*Array(history)) }
  end
end