Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dda85eef7463
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4bd5abe9b344
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 6, 2014

  1. Copy the full SHA
    0c77b6d View commit details
  2. Copy the full SHA
    4bd5abe View commit details
Showing with 34 additions and 14 deletions.
  1. +32 −14 core/src/main/java/org/jruby/RubyStruct.java
  2. +2 −0 test/mri/excludes/TestTimeExtension.rb
46 changes: 32 additions & 14 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -544,19 +544,36 @@ public IRubyObject call(IRubyObject obj, boolean recur) {
/** inspect_struct
*
*/
private IRubyObject inspectStruct(final ThreadContext context) {
private IRubyObject inspectStruct(final ThreadContext context, boolean recur) {
Ruby runtime = context.runtime;
RubyArray member = __member__();
ByteList buffer = new ByteList("#<struct ".getBytes());
String cpath = getMetaClass().getRealClass().getName();
char first = cpath.charAt(0);

if (getMetaClass().getRealClass().getBaseName() != null) {
buffer.append(getMetaClass().getRealClass().getRealClass().getName().getBytes());
if (recur || first != '#') {
buffer.append(cpath.getBytes());
buffer.append(' ');
}

if (recur) {
buffer.append(":...>".getBytes());
return runtime.newString(buffer);
}

for (int i = 0,k=member.getLength(); i < k; i++) {
if (i > 0) buffer.append(',').append(' ');
// FIXME: MRI has special case for constants here
buffer.append(RubyString.objAsString(context, member.eltInternal(i)).getByteList());
if (i > 0) {
buffer.append(',').append(' ');
} else if (first != '#') {
buffer.append(' ');
}
RubySymbol slot = (RubySymbol)member.eltInternal(i);
String name = slot.toString();
if (IdUtil.isLocal(name) || IdUtil.isConstant(name)) {
buffer.append(RubyString.objAsString(context, slot).getByteList());
} else {
buffer.append(((RubyString) slot.inspect(context)).getByteList());
}
buffer.append('=');
buffer.append(inspect(context, values[i]).getByteList());
}
@@ -566,15 +583,16 @@ private IRubyObject inspectStruct(final ThreadContext context) {
}

@JRubyMethod(name = {"inspect", "to_s"})
public IRubyObject inspect(ThreadContext context) {
if (getRuntime().isInspecting(this)) return getRuntime().newString("#<struct " + getMetaClass().getRealClass().getName() + ":...>");
public IRubyObject inspect(final ThreadContext context) {
final Ruby runtime = context.runtime;

try {
getRuntime().registerInspecting(this);
return inspectStruct(context);
} finally {
getRuntime().unregisterInspecting(this);
}
// recursion guard
return runtime.execRecursiveOuter(new Ruby.RecursiveFunction() {
@Override
public IRubyObject call(IRubyObject obj, boolean recur) {
return inspectStruct(context, recur);
}
}, this);
}

@JRubyMethod(name = {"to_a", "values"})
2 changes: 2 additions & 0 deletions test/mri/excludes/TestTimeExtension.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
exclude :test_completion_with_different_timezone, "needs investigation"
exclude :test_encode_xmlschema, "needs investigation"
exclude :test_huge_precision, "needs investigation"
exclude :test_strptime, "needs investigation"
exclude :test_xmlschema, "needs investigation"
exclude :test_zone_0000, "needs investigation"