Skip to content

Commit

Permalink
Showing 3 changed files with 54 additions and 21 deletions.
65 changes: 44 additions & 21 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -240,40 +240,63 @@ public RubyUnboundMethod unbind() {
@JRubyMethod(name = {"inspect", "to_s"})
@Override
public IRubyObject inspect() {
StringBuilder str = new StringBuilder(24).append("#<");
char sharp = '#';
Ruby runtime = getRuntime();
ThreadContext context = runtime.getCurrentContext();

RubyString str = RubyString.newString(runtime, "#<");
String sharp = "#";

str.append(getMetaClass().getRealClass().getName()).append(": ");
str.catString(getType().getName()).catString(": ");

RubyModule definedClass;
RubyModule mklass = method.getImplementationClass();

if (method instanceof AliasMethod) {
definedClass = method.getRealMethod().getImplementationClass();
}
else {
definedClass = method.getDefinedClass();
}

if (definedClass.isIncluded()) {
definedClass = definedClass.getMetaClass();
}

if (implementationModule.isSingleton()) {
IRubyObject attached = ((MetaClass) implementationModule).getAttached();
if (receiver == null) {
str.append(implementationModule.inspect().toString());
str.cat19(inspect(context, implementationModule).convertToString());
} else if (receiver == attached) {
str.append(attached.inspect().toString());
sharp = '.';
str.cat19(inspect(context, attached).convertToString());
sharp = ".";
} else {
str.append(receiver.inspect().toString());
str.append('(').append(attached.inspect().toString()).append(')');
sharp = '.';
str.cat19(inspect(context, receiver).convertToString());
str.catString("(");
str.cat19(inspect(context, attached).convertToString());
str.catString(")");
sharp = ".";
}
} else {
str.append(originModule.getName());
str.catString(originModule.getName());
if (implementationModule != originModule) {
str.append('(').append(implementationModule.getName()).append(')');
str.catString("(");
str.catString(implementationModule.getName());
str.catString(")");
}
}

str.append(sharp).append(methodName); // (real-name) if alias
final String realName= method.getRealMethod().getName();
if ( realName != null && ! methodName.equals(realName) ) {
str.append('(').append(realName).append(')');
str.catString(sharp);
str.catString(this.methodName);
if (!methodName.equals(method.getName())) {
str.catString("(");
str.catString(method.getName());
str.catString(")");
}
str.append('>');

RubyString res = RubyString.newString(getRuntime(), str);
res.setTaint(isTaint());
return res;
if (method.isNotImplemented()) {
str.catString(" (not-implemented)");
}
str.catString(">");

return str;
}

@JRubyMethod
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1212,6 +1212,11 @@ public final void addMethodAtBootTimeOnly(String name, DynamicMethod method) {
method.setImplementationClass(methodLocation);
}

// if method does not have a name already, set it
if (method.getName() == null) {
method.setName(name);
}

methodLocation.getMethodsForWrite().put(name, method);

getRuntime().addProfiledMethod(name, method);
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -1348,6 +1348,11 @@ public final int cat19(ByteList other, int codeRange) {
return EncodingUtils.encCrStrBufCat(getRuntime(), this, other, other.getEncoding(), codeRange);
}

public final RubyString catString(String str) {
cat19(encodeBytelist(str, getEncoding()), CR_UNKNOWN);
return this;
}

public final RubyString cat(RubyString str) {
return cat(str.getByteList());
}

0 comments on commit 0cb4e8d

Please sign in to comment.