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.
124
125
126
127
128
129
130
|
# File 'lib/neovim/client.rb', line 124
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
136
137
138
|
# File 'lib/neovim/client.rb', line 136
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
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/neovim/client.rb', line 140
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
152
153
154
155
156
|
# File 'lib/neovim/client.rb', line 152
def each_with_no
each do |l|
yield l, @i
end
end
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/neovim/client.rb', line 158
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
|
132
133
134
|
# File 'lib/neovim/client.rb', line 132
def to_s
(@client.buf_get_lines @buffer, @i-1, @last, true).join $/
end
|