private static void appendFeaturesToModule(ThreadContext context, final IRubyObject self, final RubyModule module) { // assuming the user wants a collection of interfaces that can be // included together. make it so. final Ruby runtime = context.runtime; final IRubyObject java_class = module.getInstanceVariables().getInstanceVariable("@java_class"); // not allowed for existing Java interface modules if (java_class != null && java_class.isTrue()) { throw runtime.newTypeError("can not add Java interface to existing Java interface"); } // To turn a module into an "interface collection" we add a class instance // variable to hold the list of interfaces, and modify append_features // for this module to call append_features on each of those interfaces as // well synchronized (module) { if ( initInterfaceModules(self, module) ) { // true - initialized final RubyClass singleton = module.getSingletonClass(); singleton.addMethod("append_features", new AppendFeatures(singleton)); } else { // already set up append_features, just add the interface if we haven't already final RubyArray interfaceModules = getInterfaceModules(module); if ( ! interfaceModules.includes(context, self) ) { interfaceModules.append(self); } } } }
private static void appendFeaturesToModule(ThreadContext context, final IRubyObject self, final RubyModule module) { // assuming the user wants a collection of interfaces that can be // included together. make it so. final Ruby runtime = context.runtime; final IRubyObject java_class = module.getInstanceVariables().getInstanceVariable("@java_class"); // not allowed for existing Java interface modules if (java_class != null && java_class.isTrue()) { throw runtime.newTypeError("can not add Java interface to existing Java interface"); } // To turn a module into an "interface collection" we add a class instance // variable to hold the list of interfaces, and modify append_features // for this module to call append_features on each of those interfaces as // well synchronized (module) { if ( initInterfaceModules(self, module) ) { // true - initialized final RubyClass singleton = module.getSingletonClass(); singleton.addMethod("append_features", new AppendFeatures(singleton)); } else { // already set up append_features, just add the interface if we haven't already final RubyArray interfaceModules = getInterfaceModules(module); if ( ! interfaceModules.includes(context, self) ) { interfaceModules.append(self); } } } }