-
-
Save headius/f9d6108d89c97bb7b2009254e3f79409 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
public class RespondToJavaService implements BasicLibraryService { | |
@Override | |
public boolean basicLoad(Ruby ruby) throws IOException { | |
ruby.defineModule("Foo").defineClassUnder("Bar", ruby.getObject(), new ObjectAllocator() { | |
@Override | |
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { | |
return new RespondTo(runtime, klazz); | |
} | |
}).defineAnnotatedMethods(RespondTo.class); | |
return true; | |
} | |
@JRubyClass(name = "RespondTo") | |
public static class RespondTo extends RubyObject { | |
public RespondTo(Ruby runtime, RubyClass klazz) { | |
super(runtime, klazz); | |
} | |
@JRubyMethod(name = "respond_to?", required = 1, optional = 1) | |
public static IRubyObject respondTo(ThreadContext context, IRubyObject self, IRubyObject[] args) { | |
System.err.println("Custom repond_to? got called!"); | |
// below line requires `frame = true` to set up a call frame for `super` | |
// return Helpers.invokeSuper(context, this, metaClass, "respond_to?", args, Block.NULL_BLOCK); | |
// instead you can just call the default impl directly | |
return self.respondTo(context, args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment