本文整理了Java中org.jruby.RubyModule.newModule
方法的一些代码示例,展示了RubyModule.newModule
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyModule.newModule
方法的具体详情如下:
包路径:org.jruby.RubyModule
类名称:RubyModule
方法名:newModule
[英]rb_module_new
[中]rb_模块_新建
代码示例来源: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 RubyModule getOverlayModuleForWrite(ThreadContext context) {
RubyModule omod = overlayModule;
if (omod == null) {
overlayModule = omod = RubyModule.newModule(context.runtime);
}
return omod;
}
}
代码示例来源:origin: org.jruby/jruby-complete
public RubyModule getOverlayModuleForWrite(ThreadContext context) {
RubyModule omod = overlayModule;
if (omod == null) {
overlayModule = omod = RubyModule.newModule(context.runtime);
}
return omod;
}
}
代码示例来源: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: org.jruby/jruby-core
/** 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
/** 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.kill-bill.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
private void wrapWithModule(RubyBasicObject self, ParseResult result) {
// toss an anonymous module into the search path
RubyModule wrapper = RubyModule.newModule(this);
self.extend(new IRubyObject[] {wrapper});
StaticScope top = result.getStaticScope();
StaticScope newTop = staticScopeFactory.newLocalScope(null);
top.setPreviousCRefScope(newTop);
top.setModule(wrapper);
}
代码示例来源:origin: org.jruby/jruby-core
private void wrapWithModule(RubyBasicObject self, ParseResult result) {
// toss an anonymous module into the search path
RubyModule wrapper = RubyModule.newModule(this);
self.extend(new IRubyObject[] {wrapper});
StaticScope top = result.getStaticScope();
StaticScope newTop = staticScopeFactory.newLocalScope(null);
top.setPreviousCRefScope(newTop);
top.setModule(wrapper);
}
代码示例来源:origin: org.jruby/jruby-core
public static void preLoadCommon(ThreadContext context, StaticScope staticScope, boolean wrap) {
RubyModule objectClass = context.runtime.getObject();
if (wrap) {
objectClass = RubyModule.newModule(context.runtime);
}
staticScope.setModule(objectClass);
DynamicScope scope = DynamicScope.newDynamicScope(staticScope);
// Each root node has a top-level scope that we need to push
context.preScopedBody(scope);
context.preNodeEval(context.runtime.getTopSelf());
}
代码示例来源:origin: org.jruby/jruby-complete
public static void preLoadCommon(ThreadContext context, StaticScope staticScope, boolean wrap) {
RubyModule objectClass = context.runtime.getObject();
if (wrap) {
objectClass = RubyModule.newModule(context.runtime);
}
staticScope.setModule(objectClass);
DynamicScope scope = DynamicScope.newDynamicScope(staticScope);
// Each root node has a top-level scope that we need to push
context.preScopedBody(scope);
context.preNodeEval(context.runtime.getTopSelf());
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
/** this method should be used only by interpreter or compiler
*
*/
public RubyModule defineOrGetModuleUnder(String name) {
// This method is intended only for defining new modules in Ruby code
Ruby runtime = getRuntime();
IRubyObject moduleObj = getConstantAtSpecial(name);
RubyModule module;
if (moduleObj != null) {
if (!moduleObj.isModule()) throw runtime.newTypeError(name + " is not a module");
module = (RubyModule)moduleObj;
} else if (classProviders != null && (module = searchProvidersForModule(name)) != null) {
// reopen a java module
} else {
module = RubyModule.newModule(runtime, name, this, true);
}
return module;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
/** this method should be used only by interpreter or compiler
*
*/
public RubyModule defineOrGetModuleUnder(String name) {
// This method is intended only for defining new modules in Ruby code
Ruby runtime = getRuntime();
IRubyObject moduleObj = getConstantAtSpecial(name);
RubyModule module;
if (moduleObj != null) {
if (!moduleObj.isModule()) throw runtime.newTypeError(name + " is not a module");
module = (RubyModule)moduleObj;
} else if (classProviders != null && (module = searchProvidersForModule(name)) != null) {
// reopen a java module
} else {
module = RubyModule.newModule(runtime, name, this, true);
}
return module;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static void preLoadCommon(ThreadContext context, StaticScope staticScope, boolean wrap) {
RubyClass objectClass = context.runtime.getObject();
IRubyObject topLevel = context.runtime.getTopSelf();
if (wrap) {
staticScope.setModule(RubyModule.newModule(context.runtime));
} else {
staticScope.setModule(objectClass);
}
DynamicScope scope = DynamicScope.newDynamicScope(staticScope);
// Each root node has a top-level scope that we need to push
context.preScopedBody(scope);
context.preNodeEval(objectClass, topLevel);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static void preLoadCommon(ThreadContext context, StaticScope staticScope, boolean wrap) {
RubyClass objectClass = context.runtime.getObject();
IRubyObject topLevel = context.runtime.getTopSelf();
if (wrap) {
staticScope.setModule(RubyModule.newModule(context.runtime));
} else {
staticScope.setModule(objectClass);
}
DynamicScope scope = DynamicScope.newDynamicScope(staticScope);
// Each root node has a top-level scope that we need to push
context.preScopedBody(scope);
context.preNodeEval(objectClass, topLevel);
}
代码示例来源:origin: org.jruby/jruby-complete
/** this method should be used only by interpreter or compiler
*
*/
public RubyModule defineOrGetModuleUnder(String name) {
// This method is intended only for defining new modules in Ruby code
Ruby runtime = getRuntime();
IRubyObject moduleObj = getConstantAtSpecial(name);
RubyModule module;
if (moduleObj != null) {
if (!moduleObj.isModule()) throw runtime.newTypeError(str(runtime, ids(runtime, name), " is not a module"));
module = (RubyModule)moduleObj;
} else if ((module = searchProvidersForModule(name)) != null) {
// reopen a java module
} else {
module = RubyModule.newModule(runtime, name, this, true);
}
return module;
}
代码示例来源:origin: org.jruby/jruby-core
/** this method should be used only by interpreter or compiler
*
*/
public RubyModule defineOrGetModuleUnder(String name) {
// This method is intended only for defining new modules in Ruby code
Ruby runtime = getRuntime();
IRubyObject moduleObj = getConstantAtSpecial(name);
RubyModule module;
if (moduleObj != null) {
if (!moduleObj.isModule()) throw runtime.newTypeError(str(runtime, ids(runtime, name), " is not a module"));
module = (RubyModule)moduleObj;
} else if ((module = searchProvidersForModule(name)) != null) {
// reopen a java module
} else {
module = RubyModule.newModule(runtime, name, this, true);
}
return module;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
/**
* Define a new module with the given name under the given module or
* class namespace. Roughly equivalent to rb_define_module_under in MRI.
*
* @param name The name of the new module
* @param parent The class or module namespace under which to define the
* module
* @returns The new module
*/
@Extension
public RubyModule defineModuleUnder(String name, RubyModule parent) {
IRubyObject moduleObj = parent.getConstantAt(name);
boolean parentIsObject = parent == objectClass;
if (moduleObj != null ) {
if (moduleObj.isModule()) return (RubyModule)moduleObj;
if (parentIsObject) {
throw newTypeError(moduleObj.getMetaClass().getName() + " is not a module");
} else {
throw newTypeError(parent.getName() + "::" + moduleObj.getMetaClass().getName() + " is not a module");
}
}
return RubyModule.newModule(this, name, parent, !parentIsObject);
}
代码示例来源:origin: org.jruby/jruby-core
public void loadScope(IRScope scope, boolean wrap) {
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this, true) : getTopSelf();
ThreadContext context = getCurrentContext();
String file = context.getFile();
try {
ThreadContext.pushBacktrace(context, ROOT_FRAME_NAME, file, 0);
context.preNodeEval(self);
if (wrap) {
// toss an anonymous module into the search path
scope.getStaticScope().setModule(RubyModule.newModule(this));
}
runInterpreter(context, scope, self);
} finally {
context.postNodeEval();
ThreadContext.popBacktrace(context);
}
}
代码示例来源:origin: org.jruby/jruby-complete
public void loadScope(IRScope scope, boolean wrap) {
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this, true) : getTopSelf();
ThreadContext context = getCurrentContext();
String file = context.getFile();
try {
ThreadContext.pushBacktrace(context, ROOT_FRAME_NAME, file, 0);
context.preNodeEval(self);
if (wrap) {
// toss an anonymous module into the search path
scope.getStaticScope().setModule(RubyModule.newModule(this));
}
runInterpreter(context, scope, self);
} finally {
context.postNodeEval();
ThreadContext.popBacktrace(context);
}
}
内容来源于网络,如有侵权,请联系作者删除!