summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-05-23 00:45:30 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-05-23 00:48:32 +0900
commit9d39eb6b40966deeeaa23c28f0be640c56545644 (patch)
tree4aebc6cbc8dc22a196656c1cffb840c6f15c032d /range.c
parentd9b338a53f520b2dbb05555f18b8de8072300f40 (diff)
range.c (inspect_range): omit beginless "nil"
except the special case `(nil..nil)`. ``` (1..).inspect #=> "1.." (..5).inspect #=> "..5" (nil..nil).inspect #=> "nil..nil" ``` [Bug #15745]
Diffstat (limited to 'range.c')
-rw-r--r--range.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/range.c b/range.c
index 03ca38d611..271c0f2ae9 100644
--- a/range.c
+++ b/range.c
@@ -1317,10 +1317,16 @@ inspect_range(VALUE range, VALUE dummy, int recur)
if (recur) {
return rb_str_new2(EXCL(range) ? "(... ... ...)" : "(... .. ...)");
}
- str = rb_inspect(RANGE_BEG(range));
- if (!NIL_P(RANGE_END(range))) str2 = rb_inspect(RANGE_END(range));
- str = rb_str_dup(str);
+ if (!NIL_P(RANGE_BEG(range)) || NIL_P(RANGE_END(range))) {
+ str = rb_str_dup(rb_inspect(RANGE_BEG(range)));
+ }
+ else {
+ str = rb_str_new(0, 0);
+ }
rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
+ if (NIL_P(RANGE_BEG(range)) || !NIL_P(RANGE_END(range))) {
+ str2 = rb_inspect(RANGE_END(range));
+ }
if (str2 != Qundef) rb_str_append(str, str2);
OBJ_INFECT(str, range);