Module: Ripl::History
- Included in:
- Shell
- Defined in:
- lib/ripl/history.rb
Constant Summary collapse
- HISTORY_FILE =
'~/.irb_history'
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
26 |
# File 'lib/ripl/history.rb', line 26 def after_loop() super; write_history end |
#before_loop ⇒ Object
25 |
# File 'lib/ripl/history.rb', line 25 def before_loop() super; read_history end |
#get_input ⇒ Object
10 11 12 |
# File 'lib/ripl/history.rb', line 10 def get_input (history << super)[-1] end |
#history ⇒ Object
8 |
# File 'lib/ripl/history.rb', line 8 def history() @history ||= [] end |
#history_file ⇒ Object
4 5 6 |
# File 'lib/ripl/history.rb', line 4 def history_file @history_file ||= config[:history] && File.(config[:history]) end |
#read_history ⇒ Object
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_history ⇒ Object
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 |