Class: Reline::KillRing::RingBuffer
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/reline/kill_ring.rb |
Class Method Summary
- .new(max = 1024) ⇒ RingBuffer constructor
Instance Attribute Summary
- #empty? ⇒ Boolean readonly
- #head readonly
- #size readonly
Instance Method Summary
Constructor Details
.new(max = 1024) ⇒ RingBuffer
# File 'lib/reline/kill_ring.rb', line 25
def initialize(max = 1024) @max = max @size = 0 @head = nil # reading head of ring-shaped tape end
Instance Attribute Details
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/reline/kill_ring.rb', line 56
def empty? @size.zero? end
#head (readonly)
[ GitHub ]# File 'lib/reline/kill_ring.rb', line 23
attr_reader :head
#size (readonly)
[ GitHub ]# File 'lib/reline/kill_ring.rb', line 22
attr_reader :size
Instance Method Details
#<<(point)
[ GitHub ]# File 'lib/reline/kill_ring.rb', line 31
def <<(point) if @size.zero? @head = point @head.backward = @head @head.forward = @head @size = 1 elsif @size >= @max tail = @head.forward new_tail = tail.forward @head.forward = point point.backward = @head new_tail.backward = point point.forward = new_tail @head = point else tail = @head.forward @head.forward = point point.backward = @head tail.backward = point point.forward = tail @head = point @size += 1 end end