Learn more at scala-tour.com
sbt write-classpath → .classpath → scala_helper.rbsbt ~compile Scala codeguard-rspec-jruby picks up changes in .rb and .class filessbt dist → .jar.gemspec includes .jarscala_list.send(:"+=", e)java.util.(List|Map) or#to_scala + #from_scalaslides.map(_.learnings).sumfuture { ruby.scala() }Find this project under github.com/RubyAndScala/jruby_meets_scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
require("test.rb")
// Sending methods via .send or Dynamic trait
eval("[1,2,3]").send[Long](`length) must beEqualTo(3)
eval("[1,2,3]").length must beEqualTo(3)
// Ruby reflection in Scala
eval[RubyObj]("[]").isA_?(`Array) must beTrue
eval[RubyObj]("[]").respondTo_?(`length) must beTrue
// obj(something) is forwared to obj[something]
eval("['foo','bar','baz']")(0) must beEqualTo("foo")
eval("{ :foo => 1, :bar => 2, :baz => 3 }")(`foo) must beEqualTo(1)
// Cast to trait/interface via .as[TraitName]
trait Person {
def firstname: String
def firstname_=(f: String): Unit
}
val zaphod:Person = new RubyObject(`Person, "Zaphod").as[Person]
zaphod.firstname must beEqualTo("Zaphod")
zaphod.firstname = "The Zeeb"
|