/** * Behaves similarly to {@link #setClassVar(String, IRubyObject)}. If the * specified internal variable is found in this class/module <em>or an ancestor</em>, * it is set where found. Otherwise it is set in this module. * * @param name the internal variable name * @param value the internal variable value * @see #searchInternalModuleVariable(String) */ public void setInternalModuleVariable(final String name, final IRubyObject value) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.hasInternalVariable(name)) { module.setInternalVariable(name, value); return; } } setInternalVariable(name, value); }
/** * Behaves similarly to {@link #setClassVar(String, IRubyObject)}. If the * specified internal variable is found in this class/module <em>or an ancestor</em>, * it is set where found. Otherwise it is set in this module. * * @param name the internal variable name * @param value the internal variable value * @see #searchInternalModuleVariable(String) */ public void setInternalModuleVariable(final String name, final IRubyObject value) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.hasInternalVariable(name)) { module.setInternalVariable(name, value); return; } } setInternalVariable(name, value); }
/** * Behaves similarly to {@link #setClassVar(String, IRubyObject)}. If the * specified internal variable is found in this class/module <em>or an ancestor</em>, * it is set where found. Otherwise it is set in this module. * * @param name the internal variable name * @param value the internal variable value * @see #searchInternalModuleVariable(String) */ public void setInternalModuleVariable(final String name, final IRubyObject value) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.hasInternalVariable(name)) { module.setInternalVariable(name, value); return; } } setInternalVariable(name, value); }
/** * Behaves similarly to {@link #setClassVar(String, IRubyObject)}. If the * specified internal variable is found in this class/module <em>or an ancestor</em>, * it is set where found. Otherwise it is set in this module. * * @param name the internal variable name * @param value the internal variable value * @see #searchInternalModuleVariable(String) */ public void setInternalModuleVariable(final String name, final IRubyObject value) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.hasInternalVariable(name)) { module.setInternalVariable(name, value); return; } } setInternalVariable(name, value); }
public static void define(RubyModule timeout) { // Timeout module methods timeout.defineAnnotatedMethods(Timeout.class); timeout.setInternalVariable( EXECUTOR_VARIABLE, new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), new DaemonThreadFactory())); }
public static void define(RubyModule timeout) { // Timeout module methods timeout.defineAnnotatedMethods(Timeout.class); timeout.setInternalVariable( EXECUTOR_VARIABLE, new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), new DaemonThreadFactory())); }
@JRubyMethod(name = "reference_required", module=true, optional = 1) public static IRubyObject reference_required(ThreadContext context, IRubyObject self, IRubyObject[] args) { module(self).setInternalVariable("reference_required", context.runtime.newBoolean(args.length < 1 || args[0].isTrue())); return self; } }
@JRubyMethod(name = "reference_required", module=true, optional = 1) public static IRubyObject reference_required(ThreadContext context, IRubyObject self, IRubyObject[] args) { module(self).setInternalVariable("reference_required", context.runtime.newBoolean(args.length < 1 || args[0].isTrue())); return self; } }
@JRubyMethod(name = "reference_required", module=true, optional = 1) public static IRubyObject reference_required(ThreadContext context, IRubyObject self, IRubyObject[] args) { module(self).setInternalVariable("reference_required", context.runtime.newBoolean(args.length < 1 || args[0].isTrue())); return self; } }
@JRubyMethod(name = "reference_required", module=true, optional = 1) public static IRubyObject reference_required(ThreadContext context, IRubyObject self, IRubyObject[] args) { module(self).setInternalVariable("reference_required", context.runtime.newBoolean(args.length < 1 || args[0].isTrue())); return self; } }
ancestor.setInternalVariable("__java_ovrd_methods", methodNames); } else { names.addAll(methodNames);
@JRubyMethod(name = "native_type", module=true, optional = 1) public static IRubyObject native_type(ThreadContext context, IRubyObject self, IRubyObject[] args) { RubyModule m = module(self); if (args.length == 0) { if (!m.hasInternalVariable("native_type")) { throw context.runtime.newNotImplementedError("native_type method not overridden and no native_type set"); } return (Type) m.getInternalVariable("native_type"); } else if (args.length == 1) { Type type = Util.findType(context, args[0]); m.setInternalVariable("native_type", type); return type; } else { throw context.runtime.newArgumentError("incorrect arguments"); } }
ancestor.setInternalVariable("__java_ovrd_methods", methodNames); } else { names.addAll(methodNames);
@JRubyMethod(name = "native_type", module=true, optional = 1) public static IRubyObject native_type(ThreadContext context, IRubyObject self, IRubyObject[] args) { RubyModule m = module(self); if (args.length == 0) { if (!m.hasInternalVariable("native_type")) { throw context.runtime.newNotImplementedError("native_type method not overridden and no native_type set"); } return (Type) m.getInternalVariable("native_type"); } else if (args.length == 1) { Type type = Util.findType(context, args[0]); m.setInternalVariable("native_type", type); return type; } else { throw context.runtime.newArgumentError("incorrect arguments"); } }
@JRubyMethod(name = "native_type", module=true, optional = 1) public static IRubyObject native_type(ThreadContext context, IRubyObject self, IRubyObject[] args) { RubyModule m = module(self); if (args.length == 0) { if (!m.hasInternalVariable("native_type")) { throw context.runtime.newNotImplementedError("native_type method not overridden and no native_type set"); } return (Type) m.getInternalVariable("native_type"); } else if (args.length == 1) { Type type = Util.findType(context, args[0]); m.setInternalVariable("native_type", type); return type; } else { throw context.runtime.newArgumentError("incorrect arguments"); } }
@JRubyMethod(name = "native_type", module=true, optional = 1) public static IRubyObject native_type(ThreadContext context, IRubyObject self, IRubyObject[] args) { RubyModule m = module(self); if (args.length == 0) { if (!m.hasInternalVariable("native_type")) { throw context.runtime.newNotImplementedError("native_type method not overridden and no native_type set"); } return (Type) m.getInternalVariable("native_type"); } else if (args.length == 1) { Type type = Util.findType(context, args[0]); m.setInternalVariable("native_type", type); return type; } else { throw context.runtime.newArgumentError("incorrect arguments"); } }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule jo = runtime.defineModule("Jo"); final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); jo.setInternalVariable("executor", executor); RubyClass joFuture = jo.defineClassUnder("Future", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); RubyClass joChannel = jo.defineClassUnder("Channel", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); jo.defineAnnotatedMethods(JoMethods.class); joFuture.defineAnnotatedMethods(JoFuture.class); joChannel.defineAnnotatedMethods(JoChannel.class); runtime.addFinalizer(new Finalizable() { public void finalize() { executor.shutdown(); } }); }