aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-03-09 07:57:16 -0700
committerNARUSE, Yui <naruse@airemix.jp>2020-03-14 16:15:15 +0900
commit0d24fb774d84d4a99454ce10fd343da00049a588 (patch)
treef1ec98c8cc5a5d7113093f02a78c2fcd90b5d312 /proc.c
parenteabf35a5d298c68f45dc600477fc586d7b868788 (diff)
downloadruby-0d24fb774d84d4a99454ce10fd343da00049a588.tar.gz
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] (cherry picked from commit e02bd0e713ef920e6d12c27f16548f48ec5c2cf0)
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 01890b11bb..deffe1fc06 100644
--- a/proc.c
+++ b/proc.c
@@ -2804,7 +2804,8 @@ method_inspect(VALUE method)
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
str = rb_sprintf("#<% "PRIsVALUE": ", rb_obj_class(method));
- mklass = data->klass;
+ mklass = data->iclass;
+ if (!mklass) mklass = data->klass;
if (RB_TYPE_P(mklass, T_ICLASS)) {
/* TODO: I'm not sure why mklass is T_ICLASS.
@@ -2844,6 +2845,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);