diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-06 08:42:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-06 08:42:51 +0000 |
commit | 2743b0d6082561a55c6a0d0843201f2413de93f3 (patch) | |
tree | 286e96129e18c2067016fcf0e7e645fb4785645f /range.c | |
parent | b0391268a221f233f098e39e3bc21b8a0888509e (diff) | |
download | ruby-2743b0d6082561a55c6a0d0843201f2413de93f3.tar.gz |
range.c: consider exclusive
* range.c (range_last): exclude the last number of the exclusive range
if the end is Numeric. [ruby-dev:47587] [Bug #8739]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -887,7 +887,15 @@ range_first(int argc, VALUE *argv, VALUE range) static VALUE range_last(int argc, VALUE *argv, VALUE range) { - if (argc == 0) return RANGE_END(range); + if (argc == 0) { + VALUE e = RANGE_END(range); + if (!EXCL(range)) return e; /* inclusive, the end is the last */ + /* exclusive, the last is previous to the end */ + if (FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric)) + return rb_int_pred(e); + + /* fallback to Array */ + } return rb_ary_last(argc, argv, rb_Array(range)); } |