Class: JRuby::ScalaSupport::Tuple

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/jruby/scala_support.rb

Instance Method Summary collapse

Methods included from Common

fake_identity, #scala_collection

Constructor Details

#initialize(raw, size) ⇒ Tuple

Returns a new instance of Tuple.



362
363
364
365
# File 'lib/jruby/scala_support.rb', line 362

def initialize(raw, size)
  super(raw)
  @size = size
end

Instance Method Details

#[](index) ⇒ Object



396
397
398
399
400
401
402
403
404
# File 'lib/jruby/scala_support.rb', line 396

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

Raises:



406
407
408
409
410
# File 'lib/jruby/scala_support.rb', line 406

def []=(index, value)
  raise ImmutableException,
    "Cannot assign #{value} to index #{index} on #{self
    }: collection immutable"
end

#eachObject



375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/jruby/scala_support.rb', line 375

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

Returns:

  • (Boolean)


371
372
373
# File 'lib/jruby/scala_support.rb', line 371

def empty?
  false
end

#sizeObject



367
368
369
# File 'lib/jruby/scala_support.rb', line 367

def size
  @size
end

#to_sObject



388
389
390
391
392
393
394
# File 'lib/jruby/scala_support.rb', line 388

def to_s
  first = true
  each_with_object("[") do |item, str|
    first ? first = false : str << ","
    str << item.to_s
  end << "]"
end