Skip to content

Commit 4cdf882

Browse files
committedJan 25, 2018
More alignment of Method#inspect and aliased/wrapped methods.
1 parent 73846e9 commit 4cdf882

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed
 

‎core/src/main/java/org/jruby/RubyMethod.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.jruby.internal.runtime.methods.DynamicMethod;
3838
import org.jruby.internal.runtime.methods.IRMethodArgs;
3939
import org.jruby.internal.runtime.methods.ProcMethod;
40+
import org.jruby.internal.runtime.methods.WrapperMethod;
4041
import org.jruby.runtime.ArgumentDescriptor;
4142
import org.jruby.runtime.Block;
4243
import org.jruby.runtime.ClassIndex;
@@ -249,10 +250,10 @@ public IRubyObject inspect() {
249250
str.catString(getType().getName()).catString(": ");
250251

251252
RubyModule definedClass;
252-
RubyModule mklass = method.getImplementationClass();
253+
RubyModule mklass = originModule;
253254

254-
if (method instanceof AliasMethod) {
255-
definedClass = method.getRealMethod().getImplementationClass();
255+
if (method instanceof AliasMethod || method instanceof WrapperMethod) {
256+
definedClass = method.getRealMethod().getDefinedClass();
256257
}
257258
else {
258259
definedClass = method.getDefinedClass();
@@ -262,10 +263,10 @@ public IRubyObject inspect() {
262263
definedClass = definedClass.getMetaClass();
263264
}
264265

265-
if (implementationModule.isSingleton()) {
266-
IRubyObject attached = ((MetaClass) implementationModule).getAttached();
266+
if (mklass.isSingleton()) {
267+
IRubyObject attached = ((MetaClass) mklass).getAttached();
267268
if (receiver == null) {
268-
str.cat19(inspect(context, implementationModule).convertToString());
269+
str.cat19(inspect(context, mklass).convertToString());
269270
} else if (receiver == attached) {
270271
str.cat19(inspect(context, attached).convertToString());
271272
sharp = ".";
@@ -277,10 +278,10 @@ public IRubyObject inspect() {
277278
sharp = ".";
278279
}
279280
} else {
280-
str.catString(originModule.getName());
281-
if (implementationModule != originModule) {
281+
str.catString(mklass.getName());
282+
if (definedClass != mklass) {
282283
str.catString("(");
283-
str.catString(implementationModule.getName());
284+
str.catString(definedClass.getName());
284285
str.catString(")");
285286
}
286287
}

‎core/src/main/java/org/jruby/internal/runtime/methods/AliasMethod.java

+23-25
Original file line numberDiff line numberDiff line change
@@ -42,67 +42,65 @@
4242
*/
4343
public class AliasMethod extends DynamicMethod {
4444
private DynamicMethod oldMethod;
45-
private String oldName;
4645

4746
public AliasMethod(RubyModule implementationClass, DynamicMethod oldMethod, String oldName) {
48-
super(implementationClass, oldMethod.getVisibility());
47+
super(implementationClass, oldMethod.getVisibility(), oldName);
4948

50-
this.oldName = oldName;
5149
this.oldMethod = oldMethod;
5250
}
5351

5452
@Override
55-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name) {
56-
return oldMethod.call(context, self, klazz, oldName);
53+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused) {
54+
return oldMethod.call(context, self, klazz, name);
5755
}
5856

5957
@Override
60-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg) {
61-
return oldMethod.call(context, self, klazz, oldName, arg);
58+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg) {
59+
return oldMethod.call(context, self, klazz, name, arg);
6260
}
6361

6462
@Override
65-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg1, IRubyObject arg2) {
66-
return oldMethod.call(context, self, klazz, oldName, arg1, arg2);
63+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg1, IRubyObject arg2) {
64+
return oldMethod.call(context, self, klazz, name, arg1, arg2);
6765
}
6866

6967
@Override
70-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
71-
return oldMethod.call(context, self, klazz, oldName, arg1, arg2, arg3);
68+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
69+
return oldMethod.call(context, self, klazz, name, arg1, arg2, arg3);
7270
}
7371

7472
@Override
75-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args) {
76-
return oldMethod.call(context, self, klazz, oldName, args);
73+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject[] args) {
74+
return oldMethod.call(context, self, klazz, name, args);
7775
}
7876

7977
@Override
80-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, Block block) {
81-
return oldMethod.call(context, self, klazz, oldName, block);
78+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, Block block) {
79+
return oldMethod.call(context, self, klazz, name, block);
8280
}
8381

8482
@Override
85-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg1, Block block) {
86-
return oldMethod.call(context, self, klazz, oldName, arg1, block);
83+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg1, Block block) {
84+
return oldMethod.call(context, self, klazz, name, arg1, block);
8785
}
8886

8987
@Override
90-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg1, IRubyObject arg2, Block block) {
91-
return oldMethod.call(context, self, klazz, oldName, arg1, arg2, block);
88+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg1, IRubyObject arg2, Block block) {
89+
return oldMethod.call(context, self, klazz, name, arg1, arg2, block);
9290
}
9391

9492
@Override
95-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
96-
return oldMethod.call(context, self, klazz, oldName, arg1, arg2, arg3, block);
93+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
94+
return oldMethod.call(context, self, klazz, name, arg1, arg2, arg3, block);
9795
}
9896

9997
@Override
100-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args, Block block) {
101-
return oldMethod.call(context, self, klazz, oldName, args, block);
98+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String unused, IRubyObject[] args, Block block) {
99+
return oldMethod.call(context, self, klazz, name, args, block);
102100
}
103101

104102
public DynamicMethod dup() {
105-
return new AliasMethod(implementationClass, oldMethod, oldName);
103+
return new AliasMethod(implementationClass, oldMethod, name);
106104
}
107105

108106
@Override
@@ -111,7 +109,7 @@ public Arity getArity(){
111109
}
112110

113111
public String getOldName() {
114-
return oldName;
112+
return name;
115113
}
116114

117115
@Override

0 commit comments

Comments
 (0)
Please sign in to comment.