Class: Neovim::Lines
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/neovim/client.rb
Instance Method Summary
collapse
Constructor Details
#initialize(client, range) ⇒ Lines
Returns a new instance of Lines.
127
128
129
130
131
132
133
|
# File 'lib/neovim/client.rb', line 127
def initialize client, range
case client
when Buffer then @client, @buffer = client.client, client.index
else @client, @buffer = client, 0
end
@i, @last = range.begin, range.end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, **kwargs, &block) ⇒ Object
139
140
141
|
# File 'lib/neovim/client.rb', line 139
def method_missing sym, *args, **kwargs, &block
to_a.send sym, *args, **kwargs, &block
end
|
Instance Method Details
#each ⇒ Object
Also known as:
each_line
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/neovim/client.rb', line 143
def each
while @i <= @last do
@inc = 1
l, = @client.buf_get_lines @buffer, @i-1, @i, true
yield l
@i += @inc
end
ensure
@i = nil
end
|
#each_with_no ⇒ Object
155
156
157
158
159
|
# File 'lib/neovim/client.rb', line 155
def each_with_no
each do |l|
yield l, @i
end
end
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/neovim/client.rb', line 161
def map!
each do |l|
h = l.hash
m = yield l, @i
if not String === m or m.hash != h then
r = result_strings m
r.flatten!
r.each { |l| l.chomp! }
@client.buf_set_lines @buffer, @i-1, @i, true, r
@inc = r.length
@last += @inc-1
end
end
end
|
135
136
137
|
# File 'lib/neovim/client.rb', line 135
def to_s
(@client.buf_get_lines @buffer, @i-1, @last, true).join $/
end
|