summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
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 8fa7dcb..c805848 100644
--- a/range.c
+++ b/range.c
@@ -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));
}