org.jruby.RubyModule.setConstant()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(78)

本文整理了Java中org.jruby.RubyModule.setConstant方法的一些代码示例,展示了RubyModule.setConstant的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyModule.setConstant方法的具体详情如下:
包路径:org.jruby.RubyModule
类名称:RubyModule
方法名:setConstant

RubyModule.setConstant介绍

[英]Set the named constant on this module. Also, if the value provided is another Module and that module has not yet been named, assign it the specified name.
[中]在此模块上设置命名常量。此外,如果提供的值是另一个模块,且该模块尚未命名,请为其指定名称。

代码示例

代码示例来源:origin: org.jruby/jruby-complete

@Deprecated
public IRubyObject fastSetConstant(String internedName, IRubyObject value) {
  return setConstant(internedName, value);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

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) {

代码示例来源:origin: org.jruby/jruby-complete

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));
}

代码示例来源:origin: org.jruby/jruby-complete

/** rb_mod_const_set
 *
 */
@JRubyMethod(name = "const_set", required = 2)
public IRubyObject const_set(IRubyObject name, IRubyObject value) {
  return setConstant(validateConstant(name), value);
}

代码示例来源:origin: org.jruby/jruby-core

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));
}

代码示例来源:origin: org.jruby/jruby-core

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
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

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
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

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) {

代码示例来源:origin: org.jruby/jruby-complete

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;
}

代码示例来源:origin: org.jruby/jruby-core

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;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

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()));
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/** 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;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

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");
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** 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;
}

代码示例来源:origin: org.jruby/jruby-complete

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()));
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/** 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);
}

代码示例来源:origin: org.jruby/jruby-complete

@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;
}

代码示例来源:origin: org.jruby/jruby-core

@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;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@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;
}

代码示例来源:origin: org.jruby/jruby-complete

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;
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法