@Deprecated public IRubyObject fastSetConstant(String internedName, IRubyObject value) { return setConstant(internedName, value); }
void install(final RubyModule proxy) { if (proxy.getConstantAt(field.getName()) == null) { // TODO: catch exception if constant is already set by other // thread try { proxy.setConstant(field.getName(), JavaUtil.convertJavaToUsableRubyObject(proxy.getRuntime(), field.get(null))); } catch (IllegalAccessException iae) { // if we can't read it, we don't set it } } } static boolean isConstant(final Field field) {
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule JRuby = runtime.getOrCreateModule("JRuby"); RubyModule JRubyUtil = JRuby.defineModuleUnder("Util"); JRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class); JRubyUtil.setConstant("SEPARATOR", runtime.newString(org.jruby.util.cli.ArgumentProcessor.SEPARATOR)); JRubyUtil.setConstant("ON_WINDOWS", runtime.newBoolean(org.jruby.platform.Platform.IS_WINDOWS)); JRubyUtil.setConstant("ON_SOLARIS", runtime.newBoolean(org.jruby.platform.Platform.IS_SOLARIS)); }
/** rb_mod_const_set * */ @JRubyMethod(name = "const_set", required = 2) public IRubyObject const_set(IRubyObject name, IRubyObject value) { return setConstant(validateConstant(name), value); }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule JRuby = runtime.getOrCreateModule("JRuby"); RubyModule JRubyUtil = JRuby.defineModuleUnder("Util"); JRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class); JRubyUtil.setConstant("SEPARATOR", runtime.newString(org.jruby.util.cli.ArgumentProcessor.SEPARATOR)); JRubyUtil.setConstant("ON_WINDOWS", runtime.newBoolean(org.jruby.platform.Platform.IS_WINDOWS)); JRubyUtil.setConstant("ON_SOLARIS", runtime.newBoolean(org.jruby.platform.Platform.IS_SOLARIS)); }
void install(final RubyModule proxy) { final String name = field.getName(); if ( proxy.getConstantAt(name) == null ) { try { final Object value = field.get(null); proxy.setConstant(name, JavaUtil.convertJavaToUsableRubyObject(proxy.getRuntime(), value)); } catch (IllegalAccessException iae) { // if we can't read it, we don't set it } } }
void install(final RubyModule proxy) { final String name = field.getName(); if ( proxy.getConstantAt(name) == null ) { try { final Object value = field.get(null); proxy.setConstant(name, JavaUtil.convertJavaToUsableRubyObject(proxy.getRuntime(), value)); } catch (IllegalAccessException iae) { // if we can't read it, we don't set it } } }
public <E extends Enum<E>> void loadConstantSet(RubyModule module, Class<E> enumClass) { for (E e : EnumSet.allOf(enumClass)) { Constant c = (Constant) e; if (Character.isUpperCase(c.name().charAt(0))) { module.setConstant(c.name(), newFixnum(c.intValue())); } } } public void loadConstantSet(RubyModule module, String constantSetName) {
public static IRubyObject setConstantInModule(ThreadContext context, String name, IRubyObject value, IRubyObject module) { if (!(module instanceof RubyModule)) { throw context.runtime.newTypeError(str(context.runtime, ids(context.runtime, module), " is not a class/module")); } ((RubyModule) module).setConstant(name, value); return value; }
public static IRubyObject setConstantInModule(ThreadContext context, String name, IRubyObject value, IRubyObject module) { if (!(module instanceof RubyModule)) { throw context.runtime.newTypeError(str(context.runtime, ids(context.runtime, module), " is not a class/module")); } ((RubyModule) module).setConstant(name, value); return value; }
public void loadConstantSet(RubyModule module, String constantSetName) { for (Constant c : ConstantSet.getConstantSet(constantSetName)) { if (Character.isUpperCase(c.name().charAt(0))) { module.setConstant(c.name(), newFixnum(c.intValue())); } } }
/** rb_module_new/rb_define_module_id/rb_name_class/rb_set_class_path * */ public static RubyModule newModule(Ruby runtime, String name, RubyModule parent, boolean setParent) { RubyModule module = newModule(runtime); module.setBaseName(name); if (setParent) module.setParent(parent); parent.setConstant(name, module); return module; }
public IRubyObject setConstant(String internedName, IRubyObject result) { RubyModule module; if ((module = getModule()) != null) { module.setConstant(internedName, result); return result; } // TODO: wire into new exception handling mechanism throw result.getRuntime().newTypeError("no class/module to define constant"); }
/** rb_module_new/rb_define_module_id/rb_name_class/rb_set_class_path * */ public static RubyModule newModule(Ruby runtime, String name, RubyModule parent, boolean setParent) { RubyModule module = newModule(runtime); module.setBaseName(name); if (setParent) module.setParent(parent); parent.setConstant(name, module); return module; }
public void loadConstantSet(RubyModule module, String constantSetName) { for (Constant c : ConstantSet.getConstantSet(constantSetName)) { if (Character.isUpperCase(c.name().charAt(0))) { module.setConstant(c.name(), newFixnum(c.intValue())); } } }
/** rb_define_const * */ @Extension public void defineConstant(String name, IRubyObject value) { assert value != null; if (!IdUtil.isValidConstantName(name)) { throw getRuntime().newNameError("bad constant name " + name, name); } setConstant(name, value); }
@Override public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { IRubyObject value = (IRubyObject) getValue().retrieve(context, self, currScope, currDynScope, temp); RubyModule module = (RubyModule) getTarget().retrieve(context, self, currScope, currDynScope, temp); assert module != null : "MODULE should always be something"; module.setConstant(getId(), value); return null; }
@Override public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { IRubyObject value = (IRubyObject) getValue().retrieve(context, self, currScope, currDynScope, temp); RubyModule module = (RubyModule) getTarget().retrieve(context, self, currScope, currDynScope, temp); assert module != null : "MODULE should always be something"; module.setConstant(getId(), value); return null; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { IRubyObject value = (IRubyObject) getValue().retrieve(context, self, currDynScope, temp); RubyModule module = (RubyModule) getTarget().retrieve(context, self, currDynScope, temp); assert module != null : "MODULE should always be something"; module.setConstant(getRef(), value); return null; }
static RubyModule createJavaPackageClass(final Ruby runtime, final RubyModule Java) { RubyClass superClass = new BlankSlateWrapper(runtime, runtime.getModule(), runtime.getKernel()); RubyClass JavaPackage = RubyClass.newClass(runtime, superClass); JavaPackage.setMetaClass(runtime.getModule()); JavaPackage.setAllocator(ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); ((MetaClass) JavaPackage.makeMetaClass(superClass)).setAttached(JavaPackage); JavaPackage.setBaseName("JavaPackage"); JavaPackage.setParent(Java); Java.setConstant("JavaPackage", JavaPackage); // Java::JavaPackage // JavaPackage.setReifiedClass(JavaPackage.class); JavaPackage.defineAnnotatedMethods(JavaPackage.class); return JavaPackage; }