本文整理了Java中org.jruby.RubyModule.defineAlias
方法的一些代码示例,展示了RubyModule.defineAlias
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyModule.defineAlias
方法的具体详情如下:
包路径:org.jruby.RubyModule
类名称:RubyModule
方法名:defineAlias
[英]rb_alias
[中]rb_别名
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static IRubyObject defineAlias(ThreadContext context, IRubyObject self, Object newNameArg, Object oldNameArg) {
Ruby runtime = context.runtime;
RubyModule module = context.getRubyClass();
if (module == null || self instanceof RubyFixnum || self instanceof RubySymbol){
throw runtime.newTypeError("no class to make alias");
}
String newName = (newNameArg instanceof String) ?
(String) newNameArg : newNameArg.toString();
String oldName = (oldNameArg instanceof String) ?
(String) oldNameArg : oldNameArg.toString();
module.defineAlias(newName, oldName);
module.callMethod(context, "method_added", runtime.newSymbol(newName));
return runtime.getNil();
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static IRubyObject defineAlias(ThreadContext context, IRubyObject self, Object newNameArg, Object oldNameArg) {
Ruby runtime = context.runtime;
RubyModule module = context.getRubyClass();
if (module == null || self instanceof RubyFixnum || self instanceof RubySymbol){
throw runtime.newTypeError("no class to make alias");
}
String newName = (newNameArg instanceof String) ?
(String) newNameArg : newNameArg.toString();
String oldName = (oldNameArg instanceof String) ?
(String) oldNameArg : oldNameArg.toString();
module.defineAlias(newName, oldName);
module.callMethod(context, "method_added", runtime.newSymbol(newName));
return runtime.getNil();
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@Override
public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currDynScope, temp);
if (object == null || object instanceof RubyFixnum || object instanceof RubySymbol) {
throw context.runtime.newTypeError("no class to make alias");
}
String newNameString = getNewName().retrieve(context, self, currDynScope, temp).toString();
String oldNameString = getOldName().retrieve(context, self, currDynScope, temp).toString();
RubyModule module = (object instanceof RubyModule) ? (RubyModule) object : object.getMetaClass();
module.defineAlias(newNameString, oldNameString);
return null;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@Override
public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currDynScope, temp);
if (object == null || object instanceof RubyFixnum || object instanceof RubySymbol) {
throw context.runtime.newTypeError("no class to make alias");
}
String newNameString = getNewName().retrieve(context, self, currDynScope, temp).toString();
String oldNameString = getOldName().retrieve(context, self, currDynScope, temp).toString();
RubyModule module = (object instanceof RubyModule) ? (RubyModule) object : object.getMetaClass();
module.defineAlias(newNameString, oldNameString);
return null;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
String newName = newId.asJavaString();
defineAlias(newName, oldId.asJavaString());
RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId :
context.runtime.newSymbol(newName);
if (isSingleton()) {
((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym);
} else {
callMethod(context, "method_added", newSym);
}
return this;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = "alias_method", required = 2)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
RubySymbol newSym = TypeConverter.checkID(newId);
RubySymbol oldSym = TypeConverter.checkID(oldId); // MRI uses rb_to_id but we return existing symbol
defineAlias(newSym.idString(), oldSym.idString());
if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym);
} else {
callMethod(context, "method_added", newSym);
}
return this;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
String newName = newId.asJavaString();
defineAlias(newName, oldId.asJavaString());
RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId :
context.runtime.newSymbol(newName);
if (isSingleton()) {
((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym);
} else {
callMethod(context, "method_added", newSym);
}
return this;
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(name = "alias_method", required = 2)
public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) {
RubySymbol newSym = TypeConverter.checkID(newId);
RubySymbol oldSym = TypeConverter.checkID(oldId); // MRI uses rb_to_id but we return existing symbol
defineAlias(newSym.idString(), oldSym.idString());
if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym);
} else {
callMethod(context, "method_added", newSym);
}
return this;
}
代码示例来源:origin: org.jruby/jruby-core
for (String alias : aliases) singletonClass.defineAlias(alias, baseName);
for (String alias : aliases) module.defineAlias(alias, baseName);
for (String alias : aliases) singletonClass.defineAlias(alias, baseName);
代码示例来源:origin: org.jruby/jruby-complete
for (String alias : aliases) singletonClass.defineAlias(alias, baseName);
for (String alias : aliases) module.defineAlias(alias, baseName);
for (String alias : aliases) singletonClass.defineAlias(alias, baseName);
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
singletonClass.defineAlias(alias, baseName);
module.defineAlias(alias, baseName);
singletonClass.defineAlias(alias, baseName);
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
singletonClass.defineAlias(alias, baseName);
module.defineAlias(alias, baseName);
singletonClass.defineAlias(alias, baseName);
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public void populate(RubyModule cls, Class clazz) {
JavaMethod javaMethod;
DynamicMethod moduleMethod;
RubyClass singletonClass = cls.getSingletonClass();
Ruby runtime = cls.getRuntime();
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$s$0$0$newInstance(singletonClass, Visibility.PUBLIC);
populateMethod(javaMethod, -1, "newInstance", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "newInstance", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.builtin.IRubyObject.class, org.jruby.runtime.builtin.IRubyObject[].class, org.jruby.runtime.Block.class});
singletonClass.addMethodAtBootTimeOnly("new", javaMethod);
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","newInstance","new");
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$0$0$readObject(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "readObject", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "readObject", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {});
cls.addMethodAtBootTimeOnly("read_object", javaMethod);
cls.defineAlias("readObject", "read_object");
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$0$0$close(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "close", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "close", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {});
cls.addMethodAtBootTimeOnly("close", javaMethod);
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$1$0$initialize(cls, Visibility.PRIVATE);
populateMethod(javaMethod, 1, "initialize", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "initialize", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("initialize", javaMethod);
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","readObject","read_object");
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","close","close");
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","initialize","initialize");
}
static {
代码示例来源:origin: org.jruby/jruby-complete
public static void define(final Ruby runtime) {
JavaExtensions.put(runtime, java.lang.Iterable.class, (proxyClass) -> Iterable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Comparable.class, (proxyClass) -> Comparable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Throwable.class, (proxyClass) -> Throwable.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Runnable.class, (proxyClass) -> Runnable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Character.class, (proxyClass) -> Character.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Number.class, (proxyClass) -> Number.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Class.class, (proxyClass) -> Class.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.ClassLoader.class, (proxyClass) -> ClassLoader.define(runtime, (RubyClass) proxyClass));
// Java::byte[].class_eval ...
JavaExtensions.put(runtime, new byte[0].getClass(), (byteArray) -> {
byteArray.addMethod("ubyte_get", new UByteGet(byteArray));
byteArray.addMethod("ubyte_set", new UByteSet(byteArray));
});
JavaExtensions.put(runtime, java.lang.String.class, (proxyClass) -> {
proxyClass.defineAlias("to_str", "to_s");
});
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public void populate(RubyModule cls, Class clazz) {
JavaMethod javaMethod;
DynamicMethod moduleMethod;
RubyClass singletonClass = cls.getSingletonClass();
Ruby runtime = cls.getRuntime();
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$s$0$0$newInstance(singletonClass, Visibility.PUBLIC);
populateMethod(javaMethod, -1, "newInstance", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "newInstance", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.builtin.IRubyObject.class, org.jruby.runtime.builtin.IRubyObject[].class, org.jruby.runtime.Block.class});
singletonClass.addMethodAtBootTimeOnly("new", javaMethod);
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","newInstance","new");
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$0$0$readObject(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "readObject", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "readObject", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {});
cls.addMethodAtBootTimeOnly("read_object", javaMethod);
cls.defineAlias("readObject", "read_object");
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$0$0$close(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "close", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "close", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {});
cls.addMethodAtBootTimeOnly("close", javaMethod);
javaMethod = new org.jruby.ext.jruby.JRubyObjectInputStream$INVOKER$i$1$0$initialize(cls, Visibility.PRIVATE);
populateMethod(javaMethod, 1, "initialize", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.jruby.JRubyObjectInputStream.class, "initialize", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("initialize", javaMethod);
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","readObject","read_object");
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","close","close");
runtime.addBoundMethod("org.jruby.ext.jruby.JRubyObjectInputStream","initialize","initialize");
}
static {
代码示例来源:origin: org.jruby/jruby-core
public static void define(final Ruby runtime) {
JavaExtensions.put(runtime, java.lang.Iterable.class, (proxyClass) -> Iterable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Comparable.class, (proxyClass) -> Comparable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Throwable.class, (proxyClass) -> Throwable.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Runnable.class, (proxyClass) -> Runnable.define(runtime, proxyClass));
JavaExtensions.put(runtime, java.lang.Character.class, (proxyClass) -> Character.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Number.class, (proxyClass) -> Number.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.Class.class, (proxyClass) -> Class.define(runtime, (RubyClass) proxyClass));
JavaExtensions.put(runtime, java.lang.ClassLoader.class, (proxyClass) -> ClassLoader.define(runtime, (RubyClass) proxyClass));
// Java::byte[].class_eval ...
JavaExtensions.put(runtime, new byte[0].getClass(), (byteArray) -> {
byteArray.addMethod("ubyte_get", new UByteGet(byteArray));
byteArray.addMethod("ubyte_set", new UByteSet(byteArray));
});
JavaExtensions.put(runtime, java.lang.String.class, (proxyClass) -> {
proxyClass.defineAlias("to_str", "to_s");
});
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
populateMethod(javaMethod, 0, "tell", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "tell", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("tell", javaMethod);
cls.defineAlias("pos", "tell");
javaMethod = new org.jruby.RubyArgsFile$INVOKER$s$0$1$each_line(cls, Visibility.PUBLIC);
populateMethod(javaMethod, -1, "each_line", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "each_line", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class, org.jruby.runtime.builtin.IRubyObject[].class, org.jruby.runtime.Block.class});
populateMethod(javaMethod, 0, "filename", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "filename", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("filename", javaMethod);
cls.defineAlias("path", "filename");
javaMethod = new org.jruby.RubyArgsFile$INVOKER$s$0$0$eof(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "eof", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "eof", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
populateMethod(javaMethod, 0, "tell", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "tell", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("tell", javaMethod);
cls.defineAlias("pos", "tell");
javaMethod = new org.jruby.RubyArgsFile$INVOKER$s$0$1$each_line(cls, Visibility.PUBLIC);
populateMethod(javaMethod, -1, "each_line", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "each_line", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class, org.jruby.runtime.builtin.IRubyObject[].class, org.jruby.runtime.Block.class});
populateMethod(javaMethod, 0, "filename", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "filename", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
cls.addMethodAtBootTimeOnly("filename", javaMethod);
cls.defineAlias("path", "filename");
javaMethod = new org.jruby.RubyArgsFile$INVOKER$s$0$0$eof(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "eof", true, CallConfiguration.FrameNoneScopeNone, false, org.jruby.RubyArgsFile.class, "eof", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
populateMethod(javaMethod, -1, "fnmatch", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.pathname.RubyPathname.class, "fnmatch", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject[].class});
cls.addMethodAtBootTimeOnly("fnmatch", javaMethod);
cls.defineAlias("fnmatch?", "fnmatch");
javaMethod = new org.jruby.ext.pathname.RubyPathname$INVOKER$i$1$0$initialize_copy(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 1, "initialize_copy", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.pathname.RubyPathname.class, "initialize_copy", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject.class});
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
populateMethod(javaMethod, -1, "fnmatch", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.pathname.RubyPathname.class, "fnmatch", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class, org.jruby.runtime.builtin.IRubyObject[].class});
cls.addMethodAtBootTimeOnly("fnmatch", javaMethod);
cls.defineAlias("fnmatch?", "fnmatch");
javaMethod = new org.jruby.ext.pathname.RubyPathname$INVOKER$i$0$0$to_s(cls, Visibility.PUBLIC);
populateMethod(javaMethod, 0, "to_s", false, CallConfiguration.FrameNoneScopeNone, false, org.jruby.ext.pathname.RubyPathname.class, "to_s", org.jruby.runtime.builtin.IRubyObject.class, new Class[] {org.jruby.runtime.ThreadContext.class});
内容来源于网络,如有侵权,请联系作者删除!