summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 15:45:11 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 15:45:11 +0000
commitf526784e1ee21f6d2b5d130673f5c3d96761f2bb (patch)
tree4cda7a4eb87c0458aa5da95825ce428d0db96e17 /range.c
parentab9bc151e828843b9d9170754f4ba4d92ef85750 (diff)
* enum.c: Enumerable#{min,min_by,max,max_by} extended to take an
optional argument. (nmin_cmp): New function. (nmin_block_cmp): Ditto (nmin_filter): Ditto. (nmin_i): Ditto. (nmin_run): Ditto. (enum_min): Call nmin_run if the optional argument is given. (nmin_max): Ditto. (nmin_min_by): Ditto. (nmin_max_by): Ditto. * range.c: Range#{min,max} extended to take an optional argument. (range_min): Call range_first if the optional argument is given. (range_max): Call rb_call_super if the optional argument is given. [ruby-core:57111] [Feature #8887] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/range.c b/range.c
index d2d9a70..0179e20 100644
--- a/range.c
+++ b/range.c
@@ -908,8 +908,10 @@ range_last(int argc, VALUE *argv, VALUE range)
/*
* call-seq:
- * rng.min -> obj
- * rng.min {| a,b | block } -> obj
+ * rng.min -> obj
+ * rng.min {| a,b | block } -> obj
+ * rng.min(n) -> array
+ * rng.min(n) {| a,b | block } -> array
*
* Returns the minimum value in the range. Returns +nil+ if the begin
* value of the range is larger than the end value.
@@ -922,10 +924,13 @@ range_last(int argc, VALUE *argv, VALUE range)
static VALUE
-range_min(VALUE range)
+range_min(int argc, VALUE *argv, VALUE range)
{
if (rb_block_given_p()) {
- return rb_call_super(0, 0);
+ return rb_call_super(argc, argv);
+ }
+ else if (argc != 0) {
+ return range_first(argc, argv, range);
}
else {
VALUE b = RANGE_BEG(range);
@@ -940,8 +945,10 @@ range_min(VALUE range)
/*
* call-seq:
- * rng.max -> obj
- * rng.max {| a,b | block } -> obj
+ * rng.max -> obj
+ * rng.max {| a,b | block } -> obj
+ * rng.max(n) -> obj
+ * rng.max(n) {| a,b | block } -> obj
*
* Returns the maximum value in the range. Returns +nil+ if the begin
* value of the range larger than the end value.
@@ -953,13 +960,13 @@ range_min(VALUE range)
*/
static VALUE
-range_max(VALUE range)
+range_max(int argc, VALUE *argv, VALUE range)
{
VALUE e = RANGE_END(range);
int nm = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric);
- if (rb_block_given_p() || (EXCL(range) && !nm)) {
- return rb_call_super(0, 0);
+ if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
+ return rb_call_super(argc, argv);
}
else {
VALUE b = RANGE_BEG(range);
@@ -1358,8 +1365,8 @@ Init_Range(void)
rb_define_method(rb_cRange, "end", range_end, 0);
rb_define_method(rb_cRange, "first", range_first, -1);
rb_define_method(rb_cRange, "last", range_last, -1);
- rb_define_method(rb_cRange, "min", range_min, 0);
- rb_define_method(rb_cRange, "max", range_max, 0);
+ rb_define_method(rb_cRange, "min", range_min, -1);
+ rb_define_method(rb_cRange, "max", range_max, -1);
rb_define_method(rb_cRange, "size", range_size, 0);
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);