Class: Textbringer::KillRing
- Inherits:
-
Object
- Object
- Textbringer::KillRing
- Defined in:
- lib/textbringer/buffer.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #current(n = 0) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(max = 30) ⇒ KillRing
constructor
A new instance of KillRing.
- #push(str) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(max = 30) ⇒ KillRing
Returns a new instance of KillRing.
1392 1393 1394 1395 1396 |
# File 'lib/textbringer/buffer.rb', line 1392 def initialize(max = 30) @max = max @ring = [] @current = -1 end |
Instance Method Details
#clear ⇒ Object
1398 1399 1400 1401 |
# File 'lib/textbringer/buffer.rb', line 1398 def clear @ring.clear @current = -1 end |
#current(n = 0) ⇒ Object
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 |
# File 'lib/textbringer/buffer.rb', line 1415 def current(n = 0) if @ring.empty? raise EditorError, "Kill ring is empty" end @current -= n if @current < 0 @current += @ring.size end @ring[@current] end |
#empty? ⇒ Boolean
1426 1427 1428 |
# File 'lib/textbringer/buffer.rb', line 1426 def empty? @ring.empty? end |
#push(str) ⇒ Object
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/textbringer/buffer.rb', line 1403 def push(str) @current += 1 if @ring.size < @max @ring.insert(@current, str) else if @current == @max @current = 0 end @ring[@current] = str end end |
#size ⇒ Object
1430 1431 1432 |
# File 'lib/textbringer/buffer.rb', line 1430 def size @ring.size end |