Class: SXP::List
- Inherits:
-
Pair
show all
- Includes:
- Enumerable
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Pair
#dotted?, #proper?, #to_a
Constructor Details
#initialize(elements = []) {|list| ... } ⇒ List
Returns a new instance of List.
21
22
23
24
25
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 21
def initialize(elements = [], &block)
@pair = nil
unshift(*elements) unless elements.empty?
block.call(self) if block_given?
end
|
Class Method Details
.[](*elements) ⇒ Object
13
14
15
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 13
def self.[](*elements)
self.new(elements)
end
|
Instance Method Details
54
55
56
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 54
def &(other)
self.class.new(self.to_a & other.to_a)
end
|
68
69
70
71
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 68
def *(times)
result = (self.to_a * times)
result.is_a?(Array) ? self.class.new(result) : result
end
|
76
77
78
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 76
def +(other)
self.class.new(self.to_a + other.to_a)
end
|
83
84
85
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 83
def -(other)
self.class.new(self.to_a - other.to_a)
end
|
#<<(object) ⇒ Object
90
91
92
93
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 90
def <<(object)
push(object)
self
end
|
#<=>(other) ⇒ Object
98
99
100
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 98
def <=>(other)
to_a <=> other.to_a
end
|
#==(other) ⇒ Object
105
106
107
108
109
110
111
112
113
114
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 105
def ==(other)
case other
when List
self.length == other.length && to_a == other.to_a
when other.respond_to?(:to_list)
other.to_list == self
else
false
end
end
|
#[](*args) ⇒ Object
119
120
121
122
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 119
def [](*args)
result = to_a[*args]
result.is_a?(Array) ? self.class.new(result) : result end
|
#[]=(*args) ⇒ Object
127
128
129
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 127
def []=(*args)
raise NotImplementedError end
|
#assoc(object) ⇒ Object
134
135
136
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 134
def assoc(object)
raise NotImplementedError end
|
#at(index) ⇒ Object
141
142
143
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 141
def at(index)
to_a.at(index)
end
|
147
148
149
150
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 147
def clear
@pair = nil
self
end
|
#collect!(&block) ⇒ Object
154
155
156
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 154
def collect!(&block)
raise NotImplementedError end
|
160
161
162
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 160
def compact
self.class.new(to_a.compact)
end
|
166
167
168
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 166
def compact!
raise NotImplementedError end
|
#concat(other) ⇒ Object
173
174
175
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 173
def concat(other)
raise NotImplementedError end
|
#delete(object, &block) ⇒ Object
180
181
182
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 180
def delete(object, &block)
raise NotImplementedError end
|
#delete_at(index) ⇒ Object
187
188
189
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 187
def delete_at(index)
raise NotImplementedError end
|
#delete_if(&block) ⇒ Object
193
194
195
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 193
def delete_if(&block)
raise NotImplementedError end
|
#each(&block) ⇒ Enumerator
199
200
201
202
203
204
205
206
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 199
def each(&block)
pair = @pair
while pair != nil
block.call(pair.head)
pair = pair.tail
end
self
end
|
#each_index(&block) ⇒ Enumerator
210
211
212
213
214
215
216
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 210
def each_index(&block)
index = 0
each do
block.call(index)
index += 1
end
end
|
#empty? ⇒ Boolean
220
221
222
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 220
def empty?
@pair.nil?
end
|
#eql?(other) ⇒ Boolean
227
228
229
230
231
232
233
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 227
def eql?(other)
case other
when self then true
when List
self.length == other.length && to_a.eql?(other.to_a)
end
end
|
#fetch(*args, &block) ⇒ Object
238
239
240
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 238
def fetch(*args, &block)
to_a.fetch(*args, &block)
end
|
#fill(*args, &block) ⇒ Object
245
246
247
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 245
def fill(*args, &block)
raise NotImplementedError end
|
#first(count = nil) ⇒ Object
252
253
254
255
256
257
258
259
260
261
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 252
def first(count = nil)
case
when count.nil?
@pair.head unless empty?
when count == 1
empty? ? [] : [first]
when count > 1
empty? ? [] : to_a.first(count)
end
end
|
265
266
267
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 265
def flatten
raise NotImplementedError end
|
271
272
273
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 271
def flatten!
raise NotImplementedError end
|
35
36
37
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 35
def head
first
end
|
#include?(object) ⇒ Object
278
279
280
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 278
def include?(object)
to_a.include?(object)
end
|
#index(object) ⇒ Object
285
286
287
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 285
def index(object)
to_a.index(object)
end
|
#insert(index, *objects) ⇒ Object
293
294
295
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 293
def insert(index, *objects)
raise NotImplementedError end
|
29
30
31
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 29
def inspect
"(" << map { |value| value.inspect }.join(' ') << ")"
end
|
#join(separator = $,) ⇒ Object
300
301
302
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 300
def join(separator = $,)
to_a.join(separator)
end
|
#last(count = nil) ⇒ Object
307
308
309
310
311
312
313
314
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 307
def last(count = nil)
case
when count.nil?
to_a.last
else
to_a.last(count)
end
end
|
318
319
320
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 318
def length
@length ||= to_a.length
end
|
#map!(&block) ⇒ Object
324
325
326
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 324
def map!(&block)
collect!(&block)
end
|
330
331
332
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 330
def nitems
to_a.nitems
end
|
#pack(template) ⇒ Object
337
338
339
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 337
def pack(template)
to_a.pack(template)
end
|
343
344
345
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 343
def pop
raise NotImplementedError end
|
#push(*objects) ⇒ Object
350
351
352
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 350
def push(*objects)
raise NotImplementedError end
|
#rassoc(key) ⇒ Object
357
358
359
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 357
def rassoc(key)
raise NotImplementedError end
|
#reject!(&block) ⇒ Object
363
364
365
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 363
def reject!(&block)
raise NotImplementedError end
|
#replace(other_list) ⇒ Object
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 370
def replace(other_list)
case other_list
when Pair
@pair = other_list
when List
@pair = other_list.to_pair
when Array
@pair = nil
unshift(*other_list)
else
end
self
end
|
47
48
49
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 47
def rest
empty? ? false : @pair.tail
end
|
387
388
389
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 387
def reverse
self.class.new(to_a.reverse)
end
|
393
394
395
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 393
def reverse!
raise NotImplementedError end
|
#reverse_each(&block) ⇒ Object
399
400
401
402
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 399
def reverse_each(&block)
to_a.reverse_each(&block)
self
end
|
#rindex(object) ⇒ Object
407
408
409
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 407
def rindex(object)
to_a.rindex(object)
end
|
413
414
415
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 413
def shift
raise NotImplementedError end
|
419
420
421
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 419
def size
length
end
|
#slice(*args) ⇒ Object
426
427
428
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 426
def slice(*args)
self[*args]
end
|
#slice!(*args) ⇒ Object
433
434
435
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 433
def slice!(*args)
raise NotImplementedError end
|
#sort(&block) ⇒ Object
439
440
441
442
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 439
def sort(&block)
(array = to_a).sort!(&block)
self.class.new(array)
end
|
446
447
448
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 446
def sort!
raise NotImplementedError end
|
41
42
43
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 41
def tail
rest
end
|
#to_list ⇒ List
452
453
454
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 452
def to_list
self
end
|
#to_pair ⇒ Pair
458
459
460
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 458
def to_pair
@pair
end
|
464
465
466
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 464
def to_s
join
end
|
#transpose ⇒ Object
470
471
472
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 470
def transpose
self.class.new(to_a.transpose)
end
|
476
477
478
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 476
def uniq
self.class.new(to_a.uniq)
end
|
482
483
484
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 482
def uniq!
raise NotImplementedError end
|
#unshift(*objects) ⇒ Object
489
490
491
492
493
494
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 489
def unshift(*objects)
objects.reverse_each do |object|
@pair = Pair.new(object, @pair)
end
self
end
|
#values_at(*selector) ⇒ Object
499
500
501
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 499
def values_at(*selector)
self.class.new(to_a.values_at(*selector))
end
|
61
62
63
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/list.rb', line 61
def |(other)
self.class.new(self.to_a | other.to_a)
end
|