Last active
December 20, 2015 12:39
-
-
Save mcamou/6132740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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