Class: Textbringer::KillRing

Inherits:
Object
  • Object
show all
Defined in:
lib/textbringer/buffer.rb

Instance Method Summary collapse

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

#clearObject



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

Returns:

  • (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

#sizeObject



1430
1431
1432
# File 'lib/textbringer/buffer.rb', line 1430

def size
  @ring.size
end