Class: Object

Inherits:
BasicObject
Defined in:
lib/jruby/scala_support.rb

Overview

Scala <-> Ruby interoperability.

Instance Method Summary collapse

Instance Method Details

#from_scalaObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/jruby/scala_support.rb', line 329

def from_scala
  case self
  when Java::jruby.collection.MapWrapper
    self.rubyHash
  when Java::scala.collection.mutable.Map
    JRuby::ScalaSupport::Map::Mutable.new(self)
  when Java::scala.collection.Map, Java::scala.collection.immutable.Map
    JRuby::ScalaSupport::Map::Immutable.new(self)
  when Java::jruby.collection.ListWrapper
    self.rubyArray
  when Java::scala.collection.mutable.Seq
    JRuby::ScalaSupport::Seq::Mutable.new(self)
  when Java::scala.collection.Seq, Java::scala.collection.immutable.Seq
    JRuby::ScalaSupport::Seq::Immutable.new(self)
  when Java::scala.Product
    match = self.class.to_s.match(/^Java::Scala::Tuple(\d+)$/)
    if match
      size = match[1].to_i
      JRuby::ScalaSupport::Tuple.new(self, size)
    else
      self
    end
  when Java::jruby.collection.SetWrapper
    self.rubySet
  when Java::scala.collection.mutable.Set
    JRuby::ScalaSupport::Set::Mutable.new(self)
  when Java::scala.collection.Set, Java::scala.collection.immutable.Set,
    JRuby::ScalaSupport::Set::Immutable.new(self)
  else
    self
  end
end

#to_scalaObject



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/jruby/scala_support.rb', line 312

def to_scala
  case self
  when JRuby::ScalaSupport::Common
    self.scala_collection
  when Hash
    Java::jruby.collection.MapWrapper.new(self)
  when Set
    Java::jruby.collection.SetWrapper.new(self)
  when Array
    Java::jruby.collection.ListWrapper.new(self)
  when Symbol
    Java::scala.Symbol.apply(to_s)
  else
    self.to_java
  end
end