Class: Reline::KillRing
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/reline/kill_ring.rb
Defined Under Namespace
Modules: State
Classes: RingBuffer, RingPoint
Instance Method Summary
collapse
Constructor Details
#initialize(max = 1024) ⇒ KillRing
Returns a new instance of KillRing.
61
62
63
64
65
66
|
# File 'lib/reline/kill_ring.rb', line 61
def initialize(max = 1024)
@ring = RingBuffer.new(max)
@ring_pointer = nil
@buffer = nil
@state = State::FRESH
end
|
Instance Method Details
#append(string, before_p = false) ⇒ Object
#each ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'lib/reline/kill_ring.rb', line 116
def each
start = head = @ring.head
loop do
break if head.nil?
yield head.str
head = head.backward
break if head == start
end
end
|
#yank ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/reline/kill_ring.rb', line 96
def yank
unless @ring.empty?
@state = State::YANK
@ring_pointer = @ring.head
@ring_pointer.str
else
nil
end
end
|
#yank_pop ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/reline/kill_ring.rb', line 106
def yank_pop
if @state == State::YANK
prev_yank = @ring_pointer.str
@ring_pointer = @ring_pointer.backward
[@ring_pointer.str, prev_yank]
else
nil
end
end
|