Skip to content

Commit

Permalink
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.java.util.ArrayUtils;
import org.jruby.javasupport.JavaUtil;
@@ -4639,6 +4640,26 @@ public RubyString pack(ThreadContext context, IRubyObject obj) {
}
}

@JRubyMethod(name = "pack")
public RubyString pack(ThreadContext context, IRubyObject obj, IRubyObject maybeOpts) {
Ruby runtime = context.runtime;
IRubyObject opts = ArgsUtil.getOptionsArg(runtime, maybeOpts);
RubyString str;

try {
IRubyObject buffer = opts.convertToHash().fastARef(runtime.newSymbol("buffer"));
if (buffer != null) {
str = buffer.convertToString();
} else {
str = RubyString.newString(runtime, "");
}
return str.append(pack(context, obj));

} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(context.runtime, e);
}
}

@JRubyMethod(name = "dig", required = 1, rest = true)
public IRubyObject dig(ThreadContext context, IRubyObject[] args) {
return dig(context, args, 0);

0 comments on commit caa22d5

Please sign in to comment.