final Ruby runtime = context.runtime;
final IRubyObject result[] = new IRubyObject[] { null, null };
final ThreadContext localContext = context;
if (block.isGiven()) {
callEach(runtime, context, self, block.arity(), new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(localContext, ctx, "minmax");
IRubyObject arg = checkArgs(runtime, largs);
if (result[0] == null) {
result[0] = result[1] = arg;
} else {
if (RubyComparable.cmpint(ctx,
block.yield(ctx, runtime.newArray(arg, result[0])), arg, result[0]) < 0) {
result[0] = arg;
}
if (RubyComparable.cmpint(ctx,
block.yield(ctx, runtime.newArray(arg, result[1])), arg, result[1]) > 0) {
result[1] = arg;
}
}
return runtime.getNil();
}
});
} else {
callEach(runtime, context, self, Arity.ONE_REQUIRED, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject arg = checkArgs(runtime, largs);
synchronized (result) {
if (result[0] == null) {
result[0] = result[1] = arg;