Skip to content

Instantly share code, notes, and snippets.

@mcamou
Last active December 20, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcamou/6132740 to your computer and use it in GitHub Desktop.
Save mcamou/6132740 to your computer and use it in GitHub Desktop.
def wrap[T](obj: Any)(implicit tag: ClassTag[T]): T = {
obj match {
case t: T => t
case jrObj: JRubyObject if tag.runtimeClass == classOf[RubyObject] => new RubyObject(jrObj)
case _ if tag.runtimeClass == classOf[Nothing] || tag.runtimeClass == classOf[Unit] => null:T
case _ => throw new IllegalTypeConversion(obj.getClass, tag.runtimeClass)
}
}
def send[T](target: JRubyObject, name: Symbol, args: Any*)(implicit tag: ClassTag[T]): T = {
handleException(
wrap[T](
ruby.callMethod(target, name.name, unwrap(args:_*):_*)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment