Module: IRB::History
- Defined in:
- lib/irb/ext/history.rb
Class Attribute Summary collapse
-
.file ⇒ Object
Returns the value of attribute file.
-
.max_entries_in_overview ⇒ Object
Returns the value of attribute max_entries_in_overview.
Class Method Summary collapse
- .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 ⇒ Object
Class Attribute Details
.file ⇒ Object
Returns the value of attribute file.
12 13 14 |
# File 'lib/irb/ext/history.rb', line 12 def file @file end |
.max_entries_in_overview ⇒ Object
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
.clear! ⇒ Object
33 34 35 36 |
# File 'lib/irb/ext/history.rb', line 33 def clear! File.open(file, "w") { |f| f << "" } Readline::HISTORY.clear end |
.context ⇒ Object
20 21 22 |
# File 'lib/irb/ext/history.rb', line 20 def context IRB::Driver.current.context end |
.history(number_of_entries = max_entries_in_overview) ⇒ Object
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 |
.history!(entry_or_range) ⇒ Object
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 |
.input(source) ⇒ Object
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 |
.setup ⇒ Object
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 |
.to_a ⇒ Object
29 30 31 |
# File 'lib/irb/ext/history.rb', line 29 def to_a File.exist?(file) ? File.read(file).split("\n") : [] end |