summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2021-02-28 14:53:21 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2021-02-28 14:53:21 +0000
commit4be089c0dd720324730230c1abfe0c200d125359 (patch)
tree543ebfd021b28ab90d7f3204b96f9574128048ea /proc.c
parente31ab1a240add146943eb0492d9929c6c92174b6 (diff)
merge revision(s) e02bd0e7: [Backport #15608]
Don't display singleton class in Method#inspect unless method defined there Previously, if an object has a singleton class, and you call Object#method on the object, the resulting string would include the object's singleton class, even though the method was not defined in the singleton class. Change this so the we only show the singleton class if the method is defined in the singleton class. Fixes [Bug #15608] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/proc.c b/proc.c
index dc827c467f..caebee4466 100644
--- a/proc.c
+++ b/proc.c
@@ -2635,7 +2635,8 @@ method_inspect(VALUE method)
str = rb_sprintf("#<% "PRIsVALUE": ", rb_obj_class(method));
OBJ_INFECT_RAW(str, method);
- mklass = data->klass;
+ mklass = data->iclass;
+ if (!mklass) mklass = data->klass;
if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
defined_class = data->me->def->body.alias.original_me->owner;
@@ -2667,6 +2668,12 @@ method_inspect(VALUE method)
}
}
else {
+ mklass = data->klass;
+ if (FL_TEST(mklass, FL_SINGLETON)) {
+ do {
+ mklass = RCLASS_SUPER(mklass);
+ } while (RB_TYPE_P(mklass, T_ICLASS));
+ }
rb_str_buf_append(str, rb_inspect(mklass));
if (defined_class != mklass) {
rb_str_catf(str, "(% "PRIsVALUE")", defined_class);