summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-22 02:58:40 (GMT)
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-22 02:58:40 (GMT)
commitcae45174190b49ca3c67ca606c5f4b71e3847842 (patch)
tree1090eca387b2ffca29e09e54c9392c7f948ceab2 /range.c
parent342619300ce26f9a134249002270c5d38d5993b3 (diff)
range.c: Range#last and #max raises a RangeError if it is endless
Also, Range#min raises an error if it is endless and a comparison method is specified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/range.c b/range.c
index c2fa6ab..c47e163 100644
--- a/range.c
+++ b/range.c
@@ -1013,6 +1013,9 @@ range_first(int argc, VALUE *argv, VALUE range)
static VALUE
range_last(int argc, VALUE *argv, VALUE range)
{
+ if (NIL_P(RANGE_END(range))) {
+ rb_raise(rb_eRangeError, "cannot get the last element of endless range");
+ }
if (argc == 0) return RANGE_END(range);
return rb_ary_last(argc, argv, rb_Array(range));
}
@@ -1040,6 +1043,9 @@ static VALUE
range_min(int argc, VALUE *argv, VALUE range)
{
if (rb_block_given_p()) {
+ if (NIL_P(RANGE_END(range))) {
+ rb_raise(rb_eRangeError, "cannot get the minimum of endless range with custom comparison method");
+ }
return rb_call_super(argc, argv);
}
else if (argc != 0) {
@@ -1080,7 +1086,9 @@ 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 (NIL_P(e)) return Qnil;
+ if (NIL_P(RANGE_END(range))) {
+ rb_raise(rb_eRangeError, "cannot get the maximum of endless range");
+ }
if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
return rb_call_super(argc, argv);