import javax.script._
import java.io._
class Ruby(script:File) extends scala.Dynamic {
val engine = new ScriptEngineManager().getEngineByName("jruby").asInstanceOf[ScriptEngine with Invocable]
engine.eval(new FileReader(script));
def language() = "Ruby"
def invokeDynamic(name: String)(args: Any*) =
engine.invokeFunction(name, args.map(_.asInstanceOf[AnyRef]) : _*)
def typed[T] = error("nope")
}
val ruby = new Ruby(new File("Math.rb"))
println(ruby.language) //normal static invocation
// Doesn't compile - if we mismatch argument count/type, it does NOT get sent to invoke dynamic
// println(ruby.language(99))
//Invoke our ruby methods for doing the math!
assert(5 == ruby.sub(10, ruby.add(2, 3)))
//demonstrate undefined methods make it to method-missing
ruby.findByPersonIdAndDepartment("xyz", "acct")