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.
121
122
123
124
125
126
127
|
# File 'lib/neovim/client.rb', line 121
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
133
134
135
|
# File 'lib/neovim/client.rb', line 133
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
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/neovim/client.rb', line 137
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
149
150
151
152
153
|
# File 'lib/neovim/client.rb', line 149
def each_with_no
each do |l|
yield l, @i
end
end
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/neovim/client.rb', line 155
def map!
each do |l|
h = l.hash
m = yield l, @i
r =
case m
when String then m.lines unless m.hash == h
when Enumerable then m.map { |l| l.to_s }
when nil, false then []
end
if r then
r.each { |l| l.chomp! }
@client.buf_set_lines @buffer, @i-1, @i, true, r
@inc = r.length
@last += @inc-1
end
end
end
|
129
130
131
|
# File 'lib/neovim/client.rb', line 129
def to_s
(@client.buf_get_lines @buffer, @i-1, @last, true).join $/
end
|