Java Code Examples for org.jruby.RubyClass#includeModule()
The following examples show how to use
org.jruby.RubyClass#includeModule() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RubySchema.java From spork with Apache License 2.0 | 6 votes |
/** * This method registers the class with the given runtime. * * @param runtime an instance of the Ruby runtime * @return a RubyClass object with metadata about the registered class */ public static RubyClass define(Ruby runtime) { RubyClass result = runtime.defineClass("Schema",runtime.getObject(), ALLOCATOR); result.kindOf = new RubyModule.KindOf() { public boolean isKindOf(IRubyObject obj, RubyModule type) { return obj instanceof RubySchema; } }; result.includeModule(runtime.getEnumerable()); result.defineAnnotatedMethods(RubySchema.class); return result; }
Example 2
Source File: RubyDataBag.java From spork with Apache License 2.0 | 6 votes |
/** * This method registers the class with the given runtime. It is not necessary to do this here, * but it is simpler to associate the methods necessary to register the class with the class * itself, so on the Library side it is possible to just specify "RubyDataBag.define(runtime)". * * @param runtime an instance of the Ruby runtime * @return a RubyClass object with metadata about the registered class */ public static RubyClass define(Ruby runtime) { // This generates the class object associated with DataBag, and registers it with the // runtime. The RubyClass object has all the metadata associated with a Class itself. RubyClass result = runtime.defineClass("DataBag", runtime.getObject(), ALLOCATOR); // This registers a method which can be used to know whether a module is an // instance of the class. result.kindOf = new RubyModule.KindOf() { public boolean isKindOf(IRubyObject obj, RubyModule type) { return obj instanceof RubyDataBag; } }; // This includes the Enumerable module that we specified. result.includeModule(runtime.getEnumerable()); // This method actually reads the annotations we placed and registers // all of the methods. result.defineAnnotatedMethods(RubyDataBag.class); // This returns the RubyClass object with all the new metadata. return result; }
Example 3
Source File: ConverterProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
private static void includeModule(RubyClass clazz, String moduleName, String... moduleNames) { RubyModule module = clazz.getRuntime().getModule(moduleName); if (moduleNames != null && moduleNames.length > 0) { for (String submoduleName: moduleNames) { module = module.getModule(submoduleName); } } clazz.includeModule(module); }
Example 4
Source File: SyntaxHighlighterProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
private static void includeModule(RubyClass clazz, String moduleName, String... moduleNames) { RubyModule module = clazz.getRuntime().getModule(moduleName); if (moduleNames != null && moduleNames.length > 0) { for (String submoduleName : moduleNames) { module = module.getModule(submoduleName); } } clazz.includeModule(module); }