Class: Byebug::History
- Inherits:
-
Object
- Object
- Byebug::History
- Defined in:
- lib/byebug/history.rb
Constant Summary collapse
- DEFAULT_FILE =
File.("#{ENV['HOME']||'.'}/.byebug_hist")
- DEFAULT_MAX_SIZE =
256
Class Attribute Summary collapse
-
.file ⇒ Object
Returns the value of attribute file.
-
.max_size ⇒ Object
Returns the value of attribute max_size.
Class Method Summary collapse
Class Attribute Details
.file ⇒ Object
Returns the value of attribute file.
12 13 14 |
# File 'lib/byebug/history.rb', line 12 def file @file end |
.max_size ⇒ Object
Returns the value of attribute max_size.
12 13 14 |
# File 'lib/byebug/history.rb', line 12 def max_size @max_size end |
Class Method Details
.load ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/byebug/history.rb', line 14 def load open(@file, 'r') do |file| file.each do |line| line.chomp! Readline::HISTORY << line end end if File.exist?(@file) end |
.save ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/byebug/history.rb', line 23 def save open(@file, 'w') do |file| Readline::HISTORY.to_a.last(@max_size).each do |line| file.puts line unless line.strip.empty? end end end |
.to_s(size = @max_size) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/byebug/history.rb', line 31 def to_s(size = @max_size) n_entries = Readline::HISTORY.length < size ? Readline::HISTORY.length : size first = Readline::HISTORY.length - n_entries commands = Readline::HISTORY.to_a.last(n_entries) s = '' commands.each_with_index do |command, index| s += ("%5d %s\n" % [first + index + 1, command]) end return s end |