final Ruby runtime = context.getRuntime();
final IRubyObject result[] = new IRubyObject[] { 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) {
IRubyObject larg = checkArgs(runtime, largs);
checkContext(localContext, ctx, "max{}");
if (result[0] == null || RubyComparable.cmpint(ctx, block.yieldArray(ctx,
runtime.newArray(larg, result[0]), null, null), larg, result[0]) > 0) {
result[0] = larg;
}
return runtime.getNil();
}
});
} else {
callEach(runtime, context, self, block.arity(), new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = checkArgs(runtime, largs);
synchronized (result) {
if (result[0] == null || RubyComparable.cmpint(ctx, invokedynamic(ctx, larg, OP_CMP, result[0]), larg, result[0]) > 0) {
result[0] = larg;