org.jruby.Ruby.defineGlobalConstant()方法的使用及代码示例

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

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

Ruby.defineGlobalConstant介绍

[英]rb_define_global_const Define a constant on the global namespace (i.e. Object) with the given name and value.
[中]rb_define_global_const使用给定的名称和值在全局命名空间(即对象)上定义一个常量。

代码示例

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

@Override
  public void load(final Ruby runtime, boolean wrap) {
    RubyRipper.initRipper(runtime);
    
    runtime.getClass("Ripper").setConstant("Version", 
        runtime.newString(RIPPER_VERSION));
    
    runtime.defineGlobalConstant("SCRIPT_LINES__", runtime.getNil());
  }
}

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

@Override
  public void load(final Ruby runtime, boolean wrap) {
    RubyRipper.initRipper(runtime);
    
    runtime.getClass("Ripper").setConstant("Version", 
        runtime.newString(RIPPER_VERSION));
    
    runtime.defineGlobalConstant("SCRIPT_LINES__", runtime.getNil());
  }
}

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

@SuppressWarnings("unchecked")
private static void defineGlobalEnvConstants(Ruby runtime) {
  Map<RubyString, RubyString> environmentVariableMap = OSEnvironment.environmentVariableMap(runtime);
  RubyHash env = new CaseInsensitiveStringOnlyRubyHash(
    runtime, environmentVariableMap, runtime.getNil(),
    runtime.getInstanceConfig().isNativeEnabled() && runtime.getInstanceConfig().isUpdateNativeENVEnabled()
  );
  env.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class);
  runtime.defineGlobalConstant("ENV", env);
  runtime.setENV(env);
  // Define System.getProperties() in ENV_JAVA
  Map<RubyString, RubyString> systemPropertiesMap = OSEnvironment.systemPropertiesMap(runtime);
  RubyHash envJava = new ReadOnlySystemPropertiesHash(
      runtime, systemPropertiesMap, runtime.getNil()
  );
  envJava.setFrozen(true);
  runtime.defineGlobalConstant("ENV_JAVA", envJava);
}

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

private static void defineGlobalEnvConstants(Ruby runtime) {
  Map environmentVariableMap = null;
  OSEnvironment environment = new OSEnvironment();
  environmentVariableMap = environment.getEnvironmentVariableMap(runtime);
  
  if (environmentVariableMap == null) {
    // if the environment variables can't be obtained, define an empty ENV
    environmentVariableMap = new HashMap();
  }
  CaseInsensitiveStringOnlyRubyHash env = new CaseInsensitiveStringOnlyRubyHash(runtime,
                          environmentVariableMap, 
                          runtime.getNil(),
                          runtime.getInstanceConfig().isNativeEnabled() && 
                            runtime.getInstanceConfig().isUpdateNativeENVEnabled() );
  env.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class);
  runtime.defineGlobalConstant("ENV", env);
  runtime.setENV(env);
  // Define System.getProperties() in ENV_JAVA
  Map systemProps = environment.getSystemPropertiesMap(runtime);
  RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(
      runtime, systemProps, runtime.getNil());
  systemPropsHash.setFrozen(true);
  runtime.defineGlobalConstant("ENV_JAVA", systemPropsHash);
}

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

public static RubyClass createMatchDataClass(Ruby runtime) {
  RubyClass matchDataClass = runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
  runtime.setMatchData(matchDataClass);
  matchDataClass.index = ClassIndex.MATCHDATA;
  matchDataClass.setReifiedClass(RubyMatchData.class);
  
  runtime.defineGlobalConstant("MatchingData", matchDataClass);
  matchDataClass.kindOf = new RubyModule.JavaClassKindOf(RubyMatchData.class);
  matchDataClass.getMetaClass().undefineMethod("new");
  matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
  return matchDataClass;
}

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

public static RubyClass createMatchDataClass(Ruby runtime) {
  RubyClass matchDataClass = runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
  runtime.setMatchData(matchDataClass);
  matchDataClass.index = ClassIndex.MATCHDATA;
  matchDataClass.setReifiedClass(RubyMatchData.class);
  
  runtime.defineGlobalConstant("MatchingData", matchDataClass);
  matchDataClass.kindOf = new RubyModule.JavaClassKindOf(RubyMatchData.class);
  matchDataClass.getMetaClass().undefineMethod("new");
  matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
  return matchDataClass;
}

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

public static RubyClass createMatchDataClass(Ruby runtime) {
  RubyClass matchDataClass = runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
  runtime.setMatchData(matchDataClass);
  matchDataClass.setClassIndex(ClassIndex.MATCHDATA);
  matchDataClass.setReifiedClass(RubyMatchData.class);
  runtime.defineGlobalConstant("MatchingData", matchDataClass);
  matchDataClass.kindOf = new RubyModule.JavaClassKindOf(RubyMatchData.class);
  matchDataClass.getMetaClass().undefineMethod("new");
  matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
  return matchDataClass;
}

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

private static void defineGlobalEnvConstants(Ruby runtime) {
  Map environmentVariableMap = null;
  OSEnvironment environment = new OSEnvironment();
  environmentVariableMap = environment.getEnvironmentVariableMap(runtime);
  
  if (environmentVariableMap == null) {
    // if the environment variables can't be obtained, define an empty ENV
    environmentVariableMap = new HashMap();
  }
  CaseInsensitiveStringOnlyRubyHash env = new CaseInsensitiveStringOnlyRubyHash(runtime,
                          environmentVariableMap, 
                          runtime.getNil(),
                          runtime.getInstanceConfig().isNativeEnabled() && 
                            runtime.getInstanceConfig().isUpdateNativeENVEnabled() );
  env.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class);
  runtime.defineGlobalConstant("ENV", env);
  runtime.setENV(env);
  // Define System.getProperties() in ENV_JAVA
  Map systemProps = environment.getSystemPropertiesMap(runtime);
  RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(
      runtime, systemProps, runtime.getNil());
  systemPropsHash.setFrozen(true);
  runtime.defineGlobalConstant("ENV_JAVA", systemPropsHash);
}

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

@SuppressWarnings("unchecked")
private static void defineGlobalEnvConstants(Ruby runtime) {
  Map<RubyString, RubyString> environmentVariableMap = OSEnvironment.environmentVariableMap(runtime);
  RubyHash env = new CaseInsensitiveStringOnlyRubyHash(
    runtime, environmentVariableMap, runtime.getNil(),
    runtime.getInstanceConfig().isNativeEnabled() && runtime.getInstanceConfig().isUpdateNativeENVEnabled()
  );
  env.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class);
  runtime.defineGlobalConstant("ENV", env);
  runtime.setENV(env);
  // Define System.getProperties() in ENV_JAVA
  Map<RubyString, RubyString> systemPropertiesMap = OSEnvironment.systemPropertiesMap(runtime);
  RubyHash envJava = new ReadOnlySystemPropertiesHash(
      runtime, systemPropertiesMap, runtime.getNil()
  );
  envJava.setFrozen(true);
  runtime.defineGlobalConstant("ENV_JAVA", envJava);
}

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

public static RubyClass createMatchDataClass(Ruby runtime) {
  RubyClass matchDataClass = runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
  runtime.setMatchData(matchDataClass);
  matchDataClass.setClassIndex(ClassIndex.MATCHDATA);
  matchDataClass.setReifiedClass(RubyMatchData.class);
  runtime.defineGlobalConstant("MatchingData", matchDataClass);
  matchDataClass.kindOf = new RubyModule.JavaClassKindOf(RubyMatchData.class);
  matchDataClass.getMetaClass().undefineMethod("new");
  matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
  return matchDataClass;
}

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

IRubyObject verbose = runtime.getVerbose();
runtime.setVerbose(runtime.getNil());
runtime.defineGlobalConstant("DATA", lexerSource.getRemainingAsIO());
runtime.setVerbose(verbose);

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

IRubyObject verbose = runtime.getVerbose();
runtime.setVerbose(runtime.getNil());
runtime.defineGlobalConstant("DATA", lexerSource.getRemainingAsIO());
runtime.setVerbose(verbose);

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

runtime.setVerbose(runtime.getNil());
try {
  runtime.defineGlobalConstant("DATA", new RubyFile(runtime, file, lexerSource.getRemainingAsStream()));
} catch (IOException e) { // Not sure how to handle suddenly closed IO here?
  runtime.defineGlobalConstant("DATA", runtime.getNil());

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

public static void initArgsFile(final Ruby runtime) {
  RubyClass argfClass = runtime.defineClass("ARGFClass", runtime.getObject(), ARGF_ALLOCATOR);
  argfClass.includeModule(runtime.getEnumerable());
  argfClass.defineAnnotatedMethods(RubyArgsFile.class);
  IRubyObject argsFile = argfClass.newInstance(runtime.getCurrentContext(), new IRubyObject[] { null }, (Block) null);
  runtime.setArgsFile(argsFile);
  runtime.getGlobalVariables().defineReadonly("$<", new ArgsFileAccessor(runtime), GlobalVariable.Scope.GLOBAL);
  runtime.defineGlobalConstant("ARGF", argsFile);
  runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
}

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

runtime.setVerbose(runtime.getNil());
try {
  runtime.defineGlobalConstant("DATA", new RubyFile(runtime, file, lexerSource.getRemainingAsStream()));
} catch (IOException e) { // Not sure how to handle suddenly closed IO here?
  runtime.defineGlobalConstant("DATA", runtime.getNil());

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

public static void initArgsFile(final Ruby runtime) {
  RubyClass argfClass = runtime.defineClass("ARGFClass", runtime.getObject(), ARGF_ALLOCATOR);
  argfClass.includeModule(runtime.getEnumerable());
  argfClass.defineAnnotatedMethods(RubyArgsFile.class);
  IRubyObject argsFile = argfClass.newInstance(runtime.getCurrentContext(), new IRubyObject[] { null }, (Block) null);
  runtime.setArgsFile(argsFile);
  runtime.getGlobalVariables().defineReadonly("$<", new ArgsFileAccessor(runtime), GlobalVariable.Scope.GLOBAL);
  runtime.defineGlobalConstant("ARGF", argsFile);
  runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
}

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

public static void initArgsFile(final Ruby runtime) {
  RubyObject argsFile = new RubyObject(runtime, runtime.getObject());
  runtime.getEnumerable().extend_object(argsFile);
  runtime.setArgsFile(argsFile);
  runtime.getGlobalVariables().defineReadonly("$<", new IAccessor() {
    @Override
    public IRubyObject getValue() {
      return runtime.getArgsFile();
    }
    @Override
    public IRubyObject setValue(IRubyObject newValue) {
      throw new UnsupportedOperationException("Not supported yet.");
    }
  }, GlobalVariable.Scope.GLOBAL);
  runtime.defineGlobalConstant("ARGF", argsFile);
  
  RubyClass argfClass = argsFile.getMetaClass();
  argfClass.defineAnnotatedMethods(RubyArgsFile.class);
  runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
}

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

public static void initArgsFile(final Ruby runtime) {
  RubyObject argsFile = new RubyObject(runtime, runtime.getObject());
  runtime.getEnumerable().extend_object(argsFile);
  runtime.setArgsFile(argsFile);
  runtime.getGlobalVariables().defineReadonly("$<", new IAccessor() {
    @Override
    public IRubyObject getValue() {
      return runtime.getArgsFile();
    }
    @Override
    public IRubyObject setValue(IRubyObject newValue) {
      throw new UnsupportedOperationException("Not supported yet.");
    }
  }, GlobalVariable.Scope.GLOBAL);
  runtime.defineGlobalConstant("ARGF", argsFile);
  
  RubyClass argfClass = argsFile.getMetaClass();
  argfClass.defineAnnotatedMethods(RubyArgsFile.class);
  runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
}

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

runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", stderr), GLOBAL);
  runtime.defineGlobalConstant("STDIN", stdin);
  runtime.defineGlobalConstant("STDOUT", stdout);
  runtime.defineGlobalConstant("STDERR", stderr);
} else {
  ((RubyIO) runtime.getObject().getConstant("STDIN")).getOpenFile().setFD(stdin.getOpenFile().fd());

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

runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", stderr), GLOBAL);
  runtime.defineGlobalConstant("STDIN", stdin);
  runtime.defineGlobalConstant("STDOUT", stdout);
  runtime.defineGlobalConstant("STDERR", stderr);
} else {
  ((RubyIO) runtime.getObject().getConstant("STDIN")).getOpenFile().setFD(stdin.getOpenFile().fd());

相关文章

Ruby类方法