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

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

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

RubyModule.getConstant介绍

[英]Retrieve the named constant, invoking 'const_missing' should that be appropriate.
[中]检索命名常量,如果合适,调用“const_missing”。

代码示例

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

/**
 * Retrieve the named constant, invoking 'const_missing' should that be appropriate.
 *
 * @param name The constant to retrieve
 * @return The value for the constant, or null if not found
 */
public IRubyObject getConstant(String name) {
  return getConstant(name, true);
}

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

/**
 * Retrieve the named constant, invoking 'const_missing' should that be appropriate.
 *
 * @param name The constant to retrieve
 * @return The value for the constant, or null if not found
 */
public IRubyObject getConstant(String name) {
  return getConstant(name, true);
}

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

@JRubyMethod(name = "zlib_version", module = true, visibility = PRIVATE)
public static IRubyObject zlib_version(IRubyObject recv) {
  RubyBasicObject res = (RubyBasicObject) ((RubyModule)recv).getConstant("ZLIB_VERSION");
  // MRI behavior, enforced by tests
  res.setTaint(true);
  return res;
}

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

/** rb_mod_const_get
 *
 */
@JRubyMethod(name = "const_get", required = 1, compat = CompatVersion.RUBY1_8)
public IRubyObject const_get(IRubyObject symbol) {
  return getConstant(validateConstant(symbol.asJavaString()));
}

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

@JRubyMethod(name = "data_type")
public IRubyObject data_type() {
  checkClosed();
  return getRuntime().getModule("Zlib").getConstant("UNKNOWN");
}

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

@JRubyMethod(name = "data_type")
public IRubyObject data_type() {
  checkClosed();
  return getRuntime().getModule("Zlib").getConstant("UNKNOWN");
}

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

@JRubyMethod(name = "data_type")
public IRubyObject data_type() {
  checkClosed();
  return getRuntime().getModule("Zlib").getConstant("UNKNOWN");
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static void create(Ruby runtime) {
  RubyModule mNet = runtime.getModule("Net");
  RubyClass cBufferedIO = (RubyClass)mNet.getConstant("BufferedIO");
  cBufferedIO.defineAnnotatedMethods(NetProtocolBufferedIO.class);
  RubyModule mNativeImpl = cBufferedIO.defineModuleUnder("NativeImplementation");
  mNativeImpl.defineAnnotatedMethods(NativeImpl.class);
}

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

public static void create(Ruby runtime) {
  RubyModule mNet = runtime.getModule("Net");
  RubyClass cBufferedIO = (RubyClass)mNet.getConstant("BufferedIO");
  cBufferedIO.defineAnnotatedMethods(NetProtocolBufferedIO.class);
  RubyModule mNativeImpl = cBufferedIO.defineModuleUnder("NativeImplementation");
  mNativeImpl.defineAnnotatedMethods(NativeImpl.class);
}

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

@JRubyMethod(required = 2, optional = 1, frame = true)
  public static IRubyObject scalar(IRubyObject self, IRubyObject[] args, Block block) {
    Ruby runtime = self.getRuntime();
    ThreadContext ctx = runtime.getCurrentContext();
    IRubyObject type_id = args[0];
    IRubyObject str = args[1];
    IRubyObject style = args.length == 2 ? runtime.getNil() : args[2];
    IRubyObject scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar").callMethod(ctx, "new", new IRubyObject[]{type_id, str, style});
    outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), scalar);
    return scalar;
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "data_type")
public IRubyObject data_type() {
  checkClosed();
  return getRuntime().getModule("Zlib").getConstant("UNKNOWN");
}

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

public static RubyClass createEnumClass(Ruby runtime, RubyModule ffiModule) {
  RubyClass enumClass = ffiModule.defineClassUnder("Enum", runtime.getObject(),
      Allocator.INSTANCE);
  enumClass.defineAnnotatedMethods(Enum.class);
  enumClass.defineAnnotatedConstants(Enum.class);
  enumClass.includeModule(ffiModule.getConstant("DataConverter"));
  
  return enumClass;
}

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

public static RubyClass createEnumsClass(Ruby runtime, RubyModule ffiModule) {
  RubyClass enumsClass = ffiModule.defineClassUnder("Enums", runtime.getObject(),
      Allocator.INSTANCE);
  enumsClass.defineAnnotatedMethods(Enums.class);
  enumsClass.defineAnnotatedConstants(Enums.class);
  enumsClass.includeModule(ffiModule.getConstant("DataConverter"));
  return enumsClass;
}

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

public static RubyClass createEnumClass(Ruby runtime, RubyModule ffiModule) {
  RubyClass enumClass = ffiModule.defineClassUnder("Enum", runtime.getObject(),
      Allocator.INSTANCE);
  enumClass.defineAnnotatedMethods(Enum.class);
  enumClass.defineAnnotatedConstants(Enum.class);
  enumClass.includeModule(ffiModule.getConstant("DataConverter"));
  
  return enumClass;
}

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

@JRubyMethod(required = 1, optional = 1, frame = true)
public static IRubyObject seq(IRubyObject self, IRubyObject[] args, Block block) {
  Ruby runtime = self.getRuntime();
  ThreadContext ctx = runtime.getCurrentContext();
  IRubyObject type_id = args[0];
  IRubyObject style = args.length == 1 ? runtime.getNil() : args[1];
  IRubyObject seq = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Seq").callMethod(ctx, "new", new IRubyObject[]{type_id, RubyArray.newArray(runtime), style});
  outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), seq);
  block.yield(ctx, seq);
  return seq;
}

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

@JRubyMethod(name = "const_get", required = 1, optional = 1, compat = CompatVersion.RUBY1_9)
public IRubyObject const_get_1_9(ThreadContext context, IRubyObject[] args) {
  IRubyObject symbol = args[0];
  boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());
  // 1.9 only includes Object when inherit = true or unspecified (JRUBY-6224)
  return getConstant(validateConstant(symbol.asJavaString()), inherit, inherit);
}

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

public static RubyClass createEnumClass(Ruby runtime, RubyModule ffiModule) {
  RubyClass enumClass = ffiModule.defineClassUnder("Enum", runtime.getObject(),
      Allocator.INSTANCE);
  enumClass.defineAnnotatedMethods(Enum.class);
  enumClass.defineAnnotatedConstants(Enum.class);
  enumClass.includeModule(ffiModule.getConstant("DataConverter"));
  
  return enumClass;
}

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

public IRubyObject allocate(Ruby runtime, RubyClass klass) {
    //                     System.err.println("ALLOCATING EMITTER");
    Emitter emitter = new Emitter();
    emitter.bonus = new Extra();
    IRubyObject pobj = runtime.newData(klass, emitter);
    emitter.handler(new RubyEmitterHandler(runtime));
    emitter.outputHandler(new RubyOutputHandler(runtime));
      
    ((RubyObject)pobj).fastSetInstanceVariable("@out", ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Out").callMethod(runtime.getCurrentContext(), "new", pobj));
    return pobj;
  }
};

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

@JRubyMethod(name = "ruby", meta = true)
public static IRubyObject ruby(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.runtime;
  RubyHash configHash = (RubyHash) runtime.getModule("RbConfig").getConstant("CONFIG");
  IRubyObject bindir            = configHash.op_aref(context, runtime.newString("bindir"));
  IRubyObject ruby_install_name = configHash.op_aref(context, runtime.newString("ruby_install_name"));
  IRubyObject exeext            = configHash.op_aref(context, runtime.newString("EXEEXT"));
  return Helpers.invoke(context, runtime.getClass("File"), "join", bindir, ruby_install_name.callMethod(context, "+", exeext));
}

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

@JRubyMethod(name = "ruby", meta = true)
public static IRubyObject ruby(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.runtime;
  RubyHash configHash = (RubyHash) runtime.getModule("RbConfig").getConstant("CONFIG");
  IRubyObject bindir            = configHash.op_aref(context, runtime.newString("bindir"));
  IRubyObject ruby_install_name = configHash.op_aref(context, runtime.newString("ruby_install_name"));
  IRubyObject exeext            = configHash.op_aref(context, runtime.newString("EXEEXT"));
  return Helpers.invoke(context, runtime.getClass("File"), "join", bindir, ruby_install_name.callMethod(context, "+", exeext));
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法