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.



1315
1316
1317
1318
1319
# File 'lib/textbringer/buffer.rb', line 1315

def initialize(max = 30)
  @max = max
  @ring = []
  @current = -1
end

Instance Method Details

#clearObject



1321
1322
1323
1324
# File 'lib/textbringer/buffer.rb', line 1321

def clear
  @ring.clear
  @current = -1
end

#current(n = 0) ⇒ Object



1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
# File 'lib/textbringer/buffer.rb', line 1338

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)


1349
1350
1351
# File 'lib/textbringer/buffer.rb', line 1349

def empty?
  @ring.empty?
end

#push(str) ⇒ Object



1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
# File 'lib/textbringer/buffer.rb', line 1326

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