Module: IRB::History
- Defined in:
- lib/irb/ext/history.rb
Class Attribute Summary (collapse)
-
+ (Object) file
Returns the value of attribute file.
-
+ (Object) max_entries_in_overview
Returns the value of attribute max_entries_in_overview.
Class Method Summary (collapse)
- + (Object) clear!
- + (Object) context
- + (Object) history(number_of_entries = max_entries_in_overview)
- + (Object) history!(entry_or_range)
- + (Object) input(source)
- + (Object) setup
- + (Object) to_a
Class Attribute Details
+ (Object) file
Returns the value of attribute file
12 13 14 |
# File 'lib/irb/ext/history.rb', line 12 def file @file end |
+ (Object) max_entries_in_overview
Returns the value of attribute max_entries_in_overview
12 13 14 |
# File 'lib/irb/ext/history.rb', line 12 def max_entries_in_overview @max_entries_in_overview end |
Class Method Details
+ (Object) clear!
33 34 35 36 |
# File 'lib/irb/ext/history.rb', line 33 def clear! File.open(file, "w") { |f| f << "" } Readline::HISTORY.clear end |
+ (Object) context
20 21 22 |
# File 'lib/irb/ext/history.rb', line 20 def context IRB::Driver.current.context end |
+ (Object) history(number_of_entries = max_entries_in_overview)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/irb/ext/history.rb', line 38 def history(number_of_entries = max_entries_in_overview) history_size = Readline::HISTORY.size start_index = 0 # always remove one extra, because that's the `history' command itself if history_size <= number_of_entries end_index = history_size - 2 else end_index = history_size - 2 start_index = history_size - number_of_entries - 1 end start_index.upto(end_index) do |i| puts "#{i}: #{Readline::HISTORY[i]}" end end |
+ (Object) history!(entry_or_range)
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/irb/ext/history.rb', line 55 def history!(entry_or_range) # we don't want to execute history! again context.clear_buffer if entry_or_range.is_a?(Range) entry_or_range.to_a.each do |i| context.input_line(Readline::HISTORY[i]) end else context.input_line(Readline::HISTORY[entry_or_range]) end end |
+ (Object) input(source)
24 25 26 27 |
# File 'lib/irb/ext/history.rb', line 24 def input(source) File.open(file, "a") { |f| f.puts(source) } source end |
+ (Object) setup
14 15 16 17 18 |
# File 'lib/irb/ext/history.rb', line 14 def setup to_a.each do |source| Readline::HISTORY.push(source) end if Readline::HISTORY.to_a.empty? end |
+ (Object) to_a
29 30 31 |
# File 'lib/irb/ext/history.rb', line 29 def to_a File.exist?(file) ? File.read(file).split("\n") : [] end |