Пример #1
0
  @JRubyMethod(name = "print", rest = true, compat = CompatVersion.RUBY1_9)
  @Override
  public IRubyObject print19(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.runtime;
    if (args.length != 0) {
      for (int i = 0, j = args.length; i < j; i++) {
        append(context, args[i]);
      }
    } else {
      IRubyObject arg = runtime.getGlobalVariables().get("$_");
      append(context, arg.isNil() ? RubyString.newEmptyString(getRuntime()) : arg);
    }
    IRubyObject sep = runtime.getGlobalVariables().get("$\\");
    if (!sep.isNil()) append(context, sep);

    return runtime.getNil();
  }
Пример #2
0
  @JRubyMethod(name = "print", rest = true)
  @Override
  public IRubyObject print(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.runtime;
    if (args.length != 0) {
      for (int i = 0, j = args.length; i < j; i++) {
        append(context, args[i]);
      }
    } else {
      IRubyObject arg = runtime.getGlobalVariables().get("$_");
      append(
          context,
          arg.isNil() ? makeString(runtime, new ByteList(new byte[] {'n', 'i', 'l'})) : arg);
    }
    IRubyObject sep = runtime.getGlobalVariables().get("$\\");
    if (!sep.isNil()) append(context, sep);

    return runtime.getNil();
  }
Пример #3
0
 @JRubyMethod(name = "printf", required = 1, rest = true)
 @Override
 public IRubyObject printf(ThreadContext context, IRubyObject[] args) {
   append(context, RubyKernel.sprintf(context, this, args));
   return getRuntime().getNil();
 }