Class: JRuby::ScalaSupport::Tuple
Instance Method Summary
collapse
Methods included from Common
fake_identity, #scala_collection
Constructor Details
#initialize(raw, size) ⇒ Tuple
Returns a new instance of Tuple.
258
259
260
261
|
# File 'lib/jruby/scala_support.rb', line 258
def initialize(raw, size)
super(raw)
@size = size
end
|
Instance Method Details
#[](index) ⇒ Object
292
293
294
295
296
297
298
299
300
|
# File 'lib/jruby/scala_support.rb', line 292
def [](index)
if index < 0
@raw.send("_#{size + index + 1}")
elsif index >= size
nil
else
@raw.send("_#{index + 1}")
end
end
|
#[]=(index, value) ⇒ Object
302
303
304
305
306
|
# File 'lib/jruby/scala_support.rb', line 302
def []=(index, value)
raise ImmutableException,
"Cannot assign #{value} to index #{index} on #{self
}: collection immutable"
end
|
#blank? ⇒ Boolean
267
268
269
|
# File 'lib/jruby/scala_support.rb', line 267
def blank?
false
end
|
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/jruby/scala_support.rb', line 271
def each
if block_given?
(0...size).each do |index|
yield self[index]
end
self
else
Enumerator.new do |yielder|
self.each { |item| yielder << item }
end
end
end
|
263
264
265
|
# File 'lib/jruby/scala_support.rb', line 263
def size
@size
end
|
284
285
286
287
288
289
290
|
# File 'lib/jruby/scala_support.rb', line 284
def to_s
first = true
each_with_object("[") do |item, str|
first ? first = false : str << ","
str << item.to_s
end << "]"
end
|