Class: Drx::TkGUI::LineHistory
Overview
Manages history for an input line.
Instance Method Summary collapse
- #add(s) ⇒ Object
- #current ⇒ Object
-
#initialize ⇒ LineHistory
constructor
A new instance of LineHistory.
- #next! ⇒ Object
- #past_end? ⇒ Boolean
- #prev! ⇒ Object
Constructor Details
#initialize ⇒ LineHistory
Returns a new instance of LineHistory.
519 520 521 522 |
# File 'lib/drx/tk/app.rb', line 519 def initialize @entries = [] @pos = 0 end |
Instance Method Details
#add(s) ⇒ Object
526 527 528 529 530 |
# File 'lib/drx/tk/app.rb', line 526 def add(s) @entries.reject! { |ent| ent == s } @entries << s @pos = @entries.size end |
#current ⇒ Object
539 540 541 |
# File 'lib/drx/tk/app.rb', line 539 def current past_end? ? '' : @entries[@pos] end |
#next! ⇒ Object
535 536 537 538 |
# File 'lib/drx/tk/app.rb', line 535 def next! @pos += 1 if not past_end? current end |
#past_end? ⇒ Boolean
523 524 525 |
# File 'lib/drx/tk/app.rb', line 523 def past_end? @pos >= @entries.size end |
#prev! ⇒ Object
531 532 533 534 |
# File 'lib/drx/tk/app.rb', line 531 def prev! @pos -= 1 if @pos > 0 current end |