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.
262
263
264
265
|
# File 'lib/jruby/scala_support.rb', line 262
def initialize(raw, size)
super(raw)
@size = size
end
|
Instance Method Details
#[](index) ⇒ Object
296
297
298
299
300
301
302
303
304
|
# File 'lib/jruby/scala_support.rb', line 296
def [](index)
if index < 0
@raw.send("_#{size + index + 1}").from_scala
elsif index >= size
nil
else
@raw.send("_#{index + 1}").from_scala
end
end
|
#[]=(index, value) ⇒ Object
306
307
308
309
310
|
# File 'lib/jruby/scala_support.rb', line 306
def []=(index, value)
raise ImmutableException,
"Cannot assign #{value} to index #{index} on #{self
}: collection immutable"
end
|
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/jruby/scala_support.rb', line 275
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
|
#empty? ⇒ Boolean
271
272
273
|
# File 'lib/jruby/scala_support.rb', line 271
def empty?
false
end
|
267
268
269
|
# File 'lib/jruby/scala_support.rb', line 267
def size
@size
end
|
288
289
290
291
292
293
294
|
# File 'lib/jruby/scala_support.rb', line 288
def to_s
first = true
each_with_object("[") do |item, str|
first ? first = false : str << ","
str << item.to_s
end << "]"
end
|