-
-
Save cheald/90741003f20b8125aeae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JRubyMethod(frame = true) | |
public IRubyObject min(ThreadContext context, Block block) { | |
RubyObject receiver; | |
if (block.isGiven()) { | |
receiver = this; | |
} else { | |
int c = RubyComparable.cmpint(context, invokedynamic(context, begin, MethodNames.OP_CMP, end), begin, end); | |
boolean emptyRange = c > 0 || (c == 0 && isExclusive); | |
if(emptyRange) return context.runtime.getNil(); | |
receiver = RubyArray.newArray(context.runtime, new IRubyObject[] {begin, end}); | |
} | |
return Helpers.invokeSuper(context, receiver, block); | |
} | |
@JRubyMethod(frame = true, required = 1) | |
public IRubyObject min(ThreadContext context, IRubyObject arg, Block block) { | |
if (block.isGiven()) { | |
return Helpers.invokeSuper(context, this, arg, block); | |
} else { | |
int c = RubyComparable.cmpint(context, invokedynamic(context, begin, MethodNames.OP_CMP, end), begin, end); | |
boolean emptyRange = c > 0 || (c == 0 && isExclusive); | |
if(emptyRange) { | |
return RubyArray.newArray(context.runtime, 0); | |
} else { | |
// Shortcut - just take the first N elements. No need to sort, as ranges are implicitly sorted. | |
return first(context, arg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment