BlockComparator(ThreadContext context, Block block, IRubyObject self, CallSite gt, CallSite lt) { this.context = context == null ? self.getRuntime().getCurrentContext() : context; this.block = block; this.self = self; this.gt = gt; this.lt = lt; }
private static RubyModule module(IRubyObject obj) { if (!(obj instanceof RubyModule)) { throw obj.getRuntime().newTypeError("not a module"); } return (RubyModule) obj; }
@JRubyMethod(rest = true) public static IRubyObject java_name(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
public int read() throws IOException { if (in != null) { return in.read(); } final Ruby runtime = io.getRuntime(); IRubyObject readValue = readAdapter.call(runtime.getCurrentContext(), io, io, numOne); if (readValue.isNil()) return -1; return readValue.convertToString().getByteList().get(0) & 0xff; }
@JRubyMethod public static IRubyObject add_type(IRubyObject self, IRubyObject taguri, IRubyObject cls) { IRubyObject tags = self.callMethod(self.getRuntime().getCurrentContext(), "tags"); ((RubyHash)tags).fastASet(taguri, cls); return self.getRuntime().getNil(); }
@JRubyMethod(name = "Pathname", module = true, visibility = Visibility.PRIVATE) public static IRubyObject newPathname(IRubyObject recv, IRubyObject path) { return RubyPathname.newInstance(recv.getRuntime().getCurrentContext(), path); } }
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
@JRubyMethod(required = 1, meta = true) public static IRubyObject kill(IRubyObject receiver, IRubyObject rubyThread, Block block) { if (!(rubyThread instanceof RubyThread)) throw receiver.getRuntime().newTypeError(rubyThread, receiver.getRuntime().getThread()); return ((RubyThread)rubyThread).kill(); }
private static RubySymbol stringOrSymbol(IRubyObject obj) { if (obj instanceof RubySymbol) return (RubySymbol) obj; if (obj instanceof RubyString) return RubySymbol.newSymbol(obj.getRuntime(), obj.asJavaString().intern()); if (obj instanceof RubyFixnum) { obj.getRuntime().getWarnings().warn(ID.FIXNUMS_NOT_SYMBOLS, "do not use Fixnums as Symbols"); throw obj.getRuntime().newArgumentError("" + obj + " is not a symbol"); } IRubyObject strValue = obj.checkStringType(); if (!strValue.isNil()) return RubySymbol.newSymbol(obj.getRuntime(), obj.asJavaString().intern()); throw obj.getRuntime().newTypeError("" + obj + " is not a symbol"); }
@JRubyMethod public static IRubyObject inherited(IRubyObject recv, IRubyObject arg0) { if (!(arg0 instanceof RubyClass)) { throw recv.getRuntime().newTypeError(arg0, recv.getRuntime().getClassClass()); } JavaInterfaceTemplate.addRealImplClassNew((RubyClass)arg0); return recv.getRuntime().getNil(); } };
@Deprecated // not used public static RubyArray splatValue(IRubyObject value) { if (value.isNil()) { return value.getRuntime().newArray(value); } return arrayValue(value); }
public static PointerParameterStrategy pointerParameterStrategy(IRubyObject parameter) { PointerParameterStrategy strategy = lookupPointerParameterStrategy(parameter); if (strategy != null) { return strategy; } else if (parameter.respondsTo("to_ptr")) { IRubyObject ptr = parameter.callMethod(parameter.getRuntime().getCurrentContext(), "to_ptr"); return new DelegatingPointerParameterStrategy(ptr, pointerParameterStrategy(ptr)); } else { throw parameter.getRuntime().newTypeError("cannot convert parameter to native pointer"); } }
@JRubyMethod public static IRubyObject detect_implicit(IRubyObject self, IRubyObject val) { IRubyObject tmp = TypeConverter.convertToTypeWithCheck(val, self.getRuntime().getString(), "to_str"); if(!tmp.isNil()) { ByteList bl = ((RubyString)tmp).getByteList(); String type_id = ImplicitScanner2.matchImplicit(Pointer.create(bl.bytes, bl.begin), bl.realSize); return self.getRuntime().newString(type_id); } return RubyString.newEmptyString(self.getRuntime()); } }
@JRubyMethod(rest = true) public static IRubyObject java_implements(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
public int read() throws IOException { if (in != null) { return in.read(); } IRubyObject readValue = readAdapter.call(io.getRuntime().getCurrentContext(), io, io, numOne); int returnValue = -1; if (!readValue.isNil()) { returnValue = readValue.convertToString().getByteList().get(0) & 0xff; } return returnValue; }
@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; } }
@JRubyMethod(name = "Pathname", module = true, visibility = Visibility.PRIVATE) public static IRubyObject newPathname(IRubyObject recv, IRubyObject path) { return RubyPathname.newInstance(recv.getRuntime().getCurrentContext(), path); } }
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
@JRubyMethod(required = 1, meta = true) public static IRubyObject kill(IRubyObject receiver, IRubyObject rubyThread, Block block) { if (!(rubyThread instanceof RubyThread)) throw receiver.getRuntime().newTypeError(rubyThread, receiver.getRuntime().getThread()); return ((RubyThread)rubyThread).kill(); }
private static long other2long(IRubyObject arg) throws RaiseException { if (arg instanceof RubyFloat) return float2long((RubyFloat) arg); if (arg instanceof RubyBignum) return RubyBignum.big2long((RubyBignum) arg); if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } return arg.convertToInteger().getLongValue(); }