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

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

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

RubyModule.defineConstant介绍

[英]rb_define_const
[中]rb_define_const

代码示例

代码示例来源:origin: bazelbuild/bazel

private RubyModule buildModuleFromDescriptor(ThreadContext context) {
  Ruby runtime = context.runtime;
  Utils.checkNameAvailability(context, name.asJavaString());
  RubyModule enumModule = RubyModule.newModule(runtime);
  for (Descriptors.EnumValueDescriptor value : descriptor.getValues()) {
    enumModule.defineConstant(value.getName(), runtime.newFixnum(value.getNumber()));
  }
  enumModule.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this);
  enumModule.defineAnnotatedMethods(RubyEnum.class);
  return enumModule;
}

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

public static void createNKF(Ruby runtime) {
  final RubyModule NKF = runtime.defineModule("NKF");
  final String version = "2.1.2";
  final String relDate = "2011-09-08";
  NKF.defineConstant("NKF_VERSION", runtime.newString(version));
  NKF.defineConstant("NKF_RELEASE_DATE", runtime.newString(relDate));
  NKF.defineConstant("VERSION", runtime.newString(version + ' ' + '(' + "JRuby" + '_' + relDate + ')'));
  for ( NKFCharset charset : NKFCharset.values() ) {
    NKFCharsetMap.put(charset.value, charset.name());
    if (charset.value > 12 ) continue;
    NKF.defineConstant(charset.name(), charsetMappedValue(runtime, charset));
  }
  NKF.defineAnnotatedMethods(RubyNKF.class);
}

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

public static RubyModule createMarshalModule(Ruby runtime) {
  RubyModule module = runtime.defineModule("Marshal");
  runtime.setMarshal(module);
  module.defineAnnotatedMethods(RubyMarshal.class);
  module.defineConstant("MAJOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MAJOR));
  module.defineConstant("MINOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MINOR));
  return module;
}

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

public static void createNKF(Ruby runtime) {
  final RubyModule NKF = runtime.defineModule("NKF");
  final String version = "2.1.2";
  final String relDate = "2011-09-08";
  NKF.defineConstant("NKF_VERSION", runtime.newString(version));
  NKF.defineConstant("NKF_RELEASE_DATE", runtime.newString(relDate));
  NKF.defineConstant("VERSION", runtime.newString(version + ' ' + '(' + "JRuby" + '_' + relDate + ')'));
  for ( NKFCharset charset : NKFCharset.values() ) {
    NKFCharsetMap.put(charset.value, charset.name());
    if (charset.value > 12 ) continue;
    NKF.defineConstant(charset.name(), charsetMappedValue(runtime, charset));
  }
  NKF.defineAnnotatedMethods(RubyNKF.class);
}

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

/** Create the Math module and add it to the Ruby runtime.
 * 
 */
public static RubyModule createMathModule(Ruby runtime) {
  RubyModule result = runtime.defineModule("Math");
  runtime.setMath(result);
  
  result.defineConstant("E", RubyFloat.newFloat(runtime, Math.E));
  result.defineConstant("PI", RubyFloat.newFloat(runtime, Math.PI));
  
  result.defineAnnotatedMethods(RubyMath.class);
  return result;
}

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

public static RubyModule createMarshalModule(Ruby runtime) {
  RubyModule module = runtime.defineModule("Marshal");
  runtime.setMarshal(module);
  module.defineAnnotatedMethods(RubyMarshal.class);
  module.defineConstant("MAJOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MAJOR));
  module.defineConstant("MINOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MINOR));
  return module;
}

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

/** Create the Math module and add it to the Ruby runtime.
 * 
 */
public static RubyModule createMathModule(Ruby runtime) {
  RubyModule result = runtime.defineModule("Math");
  runtime.setMath(result);
  
  result.defineConstant("E", RubyFloat.newFloat(runtime, Math.E));
  result.defineConstant("PI", RubyFloat.newFloat(runtime, Math.PI));
  
  result.defineAnnotatedMethods(RubyMath.class);
  return result;
}

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

/** Create the Math module and add it to the Ruby runtime.
 * 
 */
public static RubyModule createMathModule(Ruby runtime) {
  RubyModule result = runtime.defineModule("Math");
  runtime.setMath(result);
  
  result.defineConstant("E", RubyFloat.newFloat(runtime, Math.E));
  result.defineConstant("PI", RubyFloat.newFloat(runtime, Math.PI));
  
  result.defineAnnotatedMethods(RubyMath.class);
  return result;
}

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

public static RubyModule createMarshalModule(Ruby runtime) {
  RubyModule module = runtime.defineModule("Marshal");
  runtime.setMarshal(module);
  module.defineAnnotatedMethods(RubyMarshal.class);
  module.defineConstant("MAJOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MAJOR));
  module.defineConstant("MINOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MINOR));
  return module;
}

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

/** Create the Math module and add it to the Ruby runtime.
 * 
 */
public static RubyModule createMathModule(Ruby runtime) {
  RubyModule result = runtime.defineModule("Math");
  runtime.setMath(result);
  
  result.defineConstant("E", RubyFloat.newFloat(runtime, Math.E));
  result.defineConstant("PI", RubyFloat.newFloat(runtime, Math.PI));
  
  result.defineAnnotatedMethods(RubyMath.class);
  return result;
}

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

public static RubyModule createMarshalModule(Ruby runtime) {
  RubyModule module = runtime.defineModule("Marshal");
  runtime.setMarshal(module);
  module.defineAnnotatedMethods(RubyMarshal.class);
  module.defineConstant("MAJOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MAJOR));
  module.defineConstant("MINOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MINOR));
  return module;
}

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

public void load(final Ruby runtime, boolean wrap) throws IOException {
    RubyModule mFcntl = runtime.defineModule("Fcntl");

    runtime.loadConstantSet(mFcntl, "Fcntl");
    runtime.loadConstantSet(mFcntl, "OpenFlags");
    mFcntl.defineConstant("FD_CLOEXEC", RubyFixnum.newFixnum(runtime, FD_CLOEXEC));
  }
}

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

public void load(final Ruby runtime, boolean wrap) throws IOException {
    RubyModule mFcntl = runtime.defineModule("Fcntl");

    runtime.loadConstantSet(mFcntl, "Fcntl");
    runtime.loadConstantSet(mFcntl, "OpenFlags");
    mFcntl.defineConstant("FD_CLOEXEC", RubyFixnum.newFixnum(runtime, FD_CLOEXEC));
  }
}

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

public void load(final Ruby runtime, boolean wrap) throws IOException {
    RubyModule mFcntl = runtime.defineModule("Fcntl");

    runtime.loadConstantSet(mFcntl, "Fcntl");
    runtime.loadConstantSet(mFcntl, "OpenFlags");
    mFcntl.defineConstant("FD_CLOEXEC", RubyFixnum.newFixnum(runtime, FD_CLOEXEC));
  }
}

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

public void load(final Ruby runtime, boolean wrap) throws IOException {
    RubyModule mFcntl = runtime.defineModule("Fcntl");

    runtime.loadConstantSet(mFcntl, "Fcntl");
    runtime.loadConstantSet(mFcntl, "OpenFlags");
    mFcntl.defineConstant("FD_CLOEXEC", RubyFixnum.newFixnum(runtime, FD_CLOEXEC));
  }
}

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

private static void defineGroupStruct(Ruby runtime) {
  IRubyObject[] args = new IRubyObject[] {
      runtime.newString("Group"),
      runtime.newSymbol("name"),
      runtime.newSymbol("passwd"),
      runtime.newSymbol("gid"),
      runtime.newSymbol("mem")
  };
  
  runtime.setGroupStruct(RubyStruct.newInstance(runtime.getStructClass(), args, Block.NULL_BLOCK));
  runtime.getEtc().defineConstant("Group", runtime.getGroupStruct());
}

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

private static void defineGroupStruct(Ruby runtime) {
  IRubyObject[] args = new IRubyObject[] {
      runtime.newString("Group"),
      runtime.newSymbol("name"),
      runtime.newSymbol("passwd"),
      runtime.newSymbol("gid"),
      runtime.newSymbol("mem")
  };
  
  runtime.setGroupStruct(RubyStruct.newInstance(runtime.getStructClass(), args, Block.NULL_BLOCK));
  runtime.getEtc().defineConstant("Group", runtime.getGroupStruct());
}

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

private static void defineGroupStruct(Ruby runtime) {
  IRubyObject[] args = new IRubyObject[] {
      runtime.newString("Group"),
      runtime.newSymbol("name"),
      runtime.newSymbol("passwd"),
      runtime.newSymbol("gid"),
      runtime.newSymbol("mem")
  };
  
  runtime.setGroupStruct(RubyStruct.newInstance(runtime.getStructClass(), args, Block.NULL_BLOCK));
  if (runtime.is1_9()) {
    runtime.getEtc().defineConstant("Group", runtime.getGroupStruct());
  }
}

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

private static void defineGroupStruct(Ruby runtime) {
  IRubyObject[] args = new IRubyObject[] {
      runtime.newString("Group"),
      runtime.newSymbol("name"),
      runtime.newSymbol("passwd"),
      runtime.newSymbol("gid"),
      runtime.newSymbol("mem")
  };
  
  runtime.setGroupStruct(RubyStruct.newInstance(runtime.getStructClass(), args, Block.NULL_BLOCK));
  if (runtime.is1_9()) {
    runtime.getEtc().defineConstant("Group", runtime.getGroupStruct());
  }
}

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

public static void createNKF(Ruby runtime) {
  RubyModule nkfModule = runtime.defineModule("NKF");
  for (NKFCharset nkf : NKFCharset.values()) {
    nkfModule.defineConstant(nkf.name(), RubyFixnum.newFixnum(runtime, nkf.getValue()));
    NKFCharsetMap.put(nkf.getValue(), nkf.name());
  }
  RubyString version = runtime.newString("2.0.7 (JRuby 2007-05-11)");
  RubyString nkfVersion = runtime.newString("2.0.7");
  RubyString nkfDate = runtime.newString("2007-05-11");
  ThreadContext context = runtime.getCurrentContext();
  version.freeze(context);
  nkfVersion.freeze(context);
  nkfDate.freeze(context);
  nkfModule.defineAnnotatedMethods(RubyNKF.class);
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法