Module: Ripl::History
- Included in:
- Shell
- Defined in:
- lib/ripl/history.rb
Instance Method Summary collapse
- #after_loop ⇒ Object
- #before_loop ⇒ Object
- #get_input ⇒ Object
- #history ⇒ Object
- #history_file ⇒ Object
- #read_history ⇒ Object
- #write_history ⇒ Object
Instance Method Details
#after_loop ⇒ Object
21 |
# File 'lib/ripl/history.rb', line 21 def after_loop() super; write_history end |
#before_loop ⇒ Object
20 |
# File 'lib/ripl/history.rb', line 20 def before_loop() super; read_history end |
#get_input ⇒ Object
8 9 10 |
# File 'lib/ripl/history.rb', line 8 def get_input (history << super)[-1] end |
#history ⇒ Object
6 |
# File 'lib/ripl/history.rb', line 6 def history() @history ||= [] end |
#history_file ⇒ Object
2 3 4 |
# File 'lib/ripl/history.rb', line 2 def history_file @history_file ||= File.(config[:history]) end |
#read_history ⇒ Object
12 13 14 15 |
# File 'lib/ripl/history.rb', line 12 def read_history File.exists?(history_file) && history.empty? && IO.readlines(history_file).each {|e| history << e.chomp } end |
#write_history ⇒ Object
17 18 19 |
# File 'lib/ripl/history.rb', line 17 def write_history File.open(history_file, 'w') {|f| f.write Array(history).join("\n") } end |