@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
private byte[] convertToBytes(IRubyObject arg) { if (arg instanceof RubyString) { return ((RubyString) arg).getBytes(); } else if (arg instanceof RubyNumeric) { return arg.asString().getBytes(); } else { throw new IllegalArgumentException("Don't know how to write a " + arg + " " + arg.getClass()); } }
public static String str(Ruby runtime, String message, IRubyObject value) { RubyString buf = runtime.newString(message); buf.cat19(value.asString()); return buf.toString(); }
public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageMiddle, IRubyObject value2, String messageEnd) { RubyString buf = runtime.newString(messageBegin); buf.cat19(value.asString()); catUTF8(runtime, buf, messageMiddle); buf.cat19(value2.asString()); catUTF8(runtime, buf, messageEnd); return buf.toString(); }
public static String str(Ruby runtime, IRubyObject value, String message) { RubyString buf = (RubyString) value.asString().dup(); catUTF8(runtime, buf, message); return buf.toString(); }
public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageEnd) { RubyString buf = runtime.newString(messageBegin); buf.cat19(value.asString()); catUTF8(runtime, buf, messageEnd); return buf.toString(); }
public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageEnd) { RubyString buf = runtime.newString(messageBegin); buf.cat19(value.asString()); catUTF8(runtime, buf, messageEnd); return buf.toString(); }
@Override public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) { IRubyObject obj = (IRubyObject) symbolName.retrieve(context, self, currScope, currDynScope, temp); String str = obj.asJavaString(); Encoding encoding = obj.asString().getByteList().getEncoding(); return context.runtime.newSymbol(str, encoding); }
@JRubyMethod(name = {"succ", "next"}) public IRubyObject succ(ThreadContext context) { Ruby runtime = context.runtime; return newSymbol(runtime, newShared(runtime).succ(context).asString().getByteList()); }
@Deprecated public static RubySymbol newSymbol(Ruby runtime, IRubyObject name) { if (name instanceof RubySymbol) { return runtime.getSymbolTable().getSymbol(((RubySymbol) name).getBytes(), false); } else if (name instanceof RubyString) { return runtime.getSymbolTable().getSymbol(((RubyString) name).getByteList(), false); } else { return newSymbol(runtime, name.asString().getByteList()); } }
@JRubyMethod(name = "to_s") public IRubyObject to_s(ThreadContext context) { final IRubyObject msg = getMessage(); if ( ! msg.isNil() ) return msg.asString(); return context.runtime.newString(getMetaClass().getRealClass().getName()); }
@JRubyMethod(name = "to_s") public IRubyObject to_s(ThreadContext context) { final IRubyObject msg = getMessage(); if ( ! msg.isNil() ) return msg.asString(); return context.runtime.newString(getMetaClass().getRealClass().getName()); }
public static RubySymbol newHardSymbol(Ruby runtime, IRubyObject name) { if (name instanceof RubySymbol) { return runtime.getSymbolTable().getSymbol(((RubySymbol) name).getBytes(), true); } else if (name instanceof RubyString) { return runtime.getSymbolTable().getSymbol(((RubyString) name).getByteList(), true); } return newSymbol(runtime, name.asString().getByteList()); }
public static RubySymbol newHardSymbol(Ruby runtime, IRubyObject name) { if (name instanceof RubySymbol) { return runtime.getSymbolTable().getSymbol(((RubySymbol) name).getBytes(), true); } else if (name instanceof RubyString) { return runtime.getSymbolTable().getSymbol(((RubyString) name).getByteList(), true); } return newSymbol(runtime, name.asString().getByteList()); }