From 50cc9341450cfbdf9a40df3d38600d8d2854a0a3 Mon Sep 17 00:00:00 2001 From: zverok Date: Wed, 20 Nov 2019 02:33:20 +0200 Subject: Update representation (discussed on ruby tracker) --- proc.c | 8 +++----- test/ruby/test_method.rb | 40 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/proc.c b/proc.c index e37ac1ceb3..9859116baf 100644 --- a/proc.c +++ b/proc.c @@ -2830,7 +2830,6 @@ method_inspect(VALUE method) { VALUE params = rb_method_parameters(method); VALUE pair, name, kind; - int arg_num = 1; const VALUE req = ID2SYM(rb_intern("req")); const VALUE opt = ID2SYM(rb_intern("opt")); const VALUE keyreq = ID2SYM(rb_intern("keyreq")); @@ -2850,8 +2849,7 @@ method_inspect(VALUE method) if (NIL_P(name) || name == Qfalse) { // FIXME: can it be reduced to switch/case? if (kind == req || kind == opt) { - name = rb_sprintf("arg%d", arg_num); - arg_num++; + name = rb_str_new2("_"); } else if (kind == rest || kind == keyrest) { name = rb_str_new2(""); } else if (kind == block) { @@ -2864,11 +2862,11 @@ method_inspect(VALUE method) if (kind == req) { rb_str_catf(str, "%"PRIsVALUE, name); } else if (kind == opt) { - rb_str_catf(str, "%"PRIsVALUE"=", name); + rb_str_catf(str, "%"PRIsVALUE"=...", name); } else if (kind == keyreq) { rb_str_catf(str, "%"PRIsVALUE":", name); } else if (kind == key) { - rb_str_catf(str, "%"PRIsVALUE": ", name); + rb_str_catf(str, "%"PRIsVALUE": ...", name); } else if (kind == rest) { rb_str_catf(str, "*%"PRIsVALUE, name); } else if (kind == keyrest) { diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index efd5fae328..be5afab05f 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -636,23 +636,23 @@ class TestMethod < Test::Unit::TestCase assert_include(method(:m0).inspect, "()") assert_include(method(:m1).inspect, "(a)") assert_include(method(:m2).inspect, "(a, b)") - assert_include(method(:mo1).inspect, "(a=, &b)") - assert_include(method(:mo2).inspect, "(a, b=)") + assert_include(method(:mo1).inspect, "(a=..., &b)") + assert_include(method(:mo2).inspect, "(a, b=...)") assert_include(method(:mo3).inspect, "(*a)") assert_include(method(:mo4).inspect, "(a, *b, &c)") assert_include(method(:mo5).inspect, "(a, *b, c)") assert_include(method(:mo6).inspect, "(a, *b, c, &d)") - assert_include(method(:mo7).inspect, "(a, b=, *c, d, &e)") - assert_include(method(:mo8).inspect, "(a, b=, *, d, &e)") - assert_include(method(:ma1).inspect, "(arg1, &b)") + assert_include(method(:mo7).inspect, "(a, b=..., *c, d, &e)") + assert_include(method(:mo8).inspect, "(a, b=..., *, d, &e)") + assert_include(method(:ma1).inspect, "(_, &b)") assert_include(method(:mk1).inspect, "(**)") assert_include(method(:mk2).inspect, "(**o)") assert_include(method(:mk3).inspect, "(a, **o)") - assert_include(method(:mk4).inspect, "(a=, **o)") - assert_include(method(:mk5).inspect, "(a, b=, **o)") - assert_include(method(:mk6).inspect, "(a, b=, c, **o)") - assert_include(method(:mk7).inspect, "(a, b=, *c, d, **o)") - assert_include(method(:mk8).inspect, "(a, b=, *c, d, e:, f: , **o)") + assert_include(method(:mk4).inspect, "(a=..., **o)") + assert_include(method(:mk5).inspect, "(a, b=..., **o)") + assert_include(method(:mk6).inspect, "(a, b=..., c, **o)") + assert_include(method(:mk7).inspect, "(a, b=..., *c, d, **o)") + assert_include(method(:mk8).inspect, "(a, b=..., *c, d, e:, f: ..., **o)") assert_include(method(:mnk).inspect, "(**nil)") end @@ -660,23 +660,23 @@ class TestMethod < Test::Unit::TestCase assert_include(self.class.instance_method(:m0).inspect, "()") assert_include(self.class.instance_method(:m1).inspect, "(a)") assert_include(self.class.instance_method(:m2).inspect, "(a, b)") - assert_include(self.class.instance_method(:mo1).inspect, "(a=, &b)") - assert_include(self.class.instance_method(:mo2).inspect, "(a, b=)") + assert_include(self.class.instance_method(:mo1).inspect, "(a=..., &b)") + assert_include(self.class.instance_method(:mo2).inspect, "(a, b=...)") assert_include(self.class.instance_method(:mo3).inspect, "(*a)") assert_include(self.class.instance_method(:mo4).inspect, "(a, *b, &c)") assert_include(self.class.instance_method(:mo5).inspect, "(a, *b, c)") assert_include(self.class.instance_method(:mo6).inspect, "(a, *b, c, &d)") - assert_include(self.class.instance_method(:mo7).inspect, "(a, b=, *c, d, &e)") - assert_include(self.class.instance_method(:mo8).inspect, "(a, b=, *, d, &e)") - assert_include(self.class.instance_method(:ma1).inspect, "(arg1, &b)") + assert_include(self.class.instance_method(:mo7).inspect, "(a, b=..., *c, d, &e)") + assert_include(self.class.instance_method(:mo8).inspect, "(a, b=..., *, d, &e)") + assert_include(self.class.instance_method(:ma1).inspect, "(_, &b)") assert_include(self.class.instance_method(:mk1).inspect, "(**)") assert_include(self.class.instance_method(:mk2).inspect, "(**o)") assert_include(self.class.instance_method(:mk3).inspect, "(a, **o)") - assert_include(self.class.instance_method(:mk4).inspect, "(a=, **o)") - assert_include(self.class.instance_method(:mk5).inspect, "(a, b=, **o)") - assert_include(self.class.instance_method(:mk6).inspect, "(a, b=, c, **o)") - assert_include(self.class.instance_method(:mk7).inspect, "(a, b=, *c, d, **o)") - assert_include(self.class.instance_method(:mk8).inspect, "(a, b=, *c, d, e:, f: , **o)") + assert_include(self.class.instance_method(:mk4).inspect, "(a=..., **o)") + assert_include(self.class.instance_method(:mk5).inspect, "(a, b=..., **o)") + assert_include(self.class.instance_method(:mk6).inspect, "(a, b=..., c, **o)") + assert_include(self.class.instance_method(:mk7).inspect, "(a, b=..., *c, d, **o)") + assert_include(self.class.instance_method(:mk8).inspect, "(a, b=..., *c, d, e:, f: ..., **o)") assert_include(self.class.instance_method(:mnk).inspect, "(**nil)") end -- cgit v1.2.3