@RubyLevelMethod(name = "sprintf", module = true) public static RubyValue sprintf(RubyValue receiver, RubyArray args) { String fmt = args.get(0).toStr(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); ps.printf(fmt, RubyKernelModule.buildFormatArg(args, 1)); ps.flush(); ps.close(); return ObjectFactory.createString(baos.toString()); }
@RubyLevelMethod(name = "printf", module = true) public static RubyValue printf(RubyValue receiver, RubyArray args) { String fmt = args.get(0).toStr(); System.out.printf(fmt, RubyKernelModule.buildFormatArg(args, 1)); return RubyConstant.QNIL; }