Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect not returning ruby String in jruby-9.0.0.0 #2517

Closed
monkstone opened this issue Jan 24, 2015 · 3 comments
Closed

inspect not returning ruby String in jruby-9.0.0.0 #2517

monkstone opened this issue Jan 24, 2015 · 3 comments

Comments

@monkstone
Copy link
Contributor

In ruby-processing I have created jruby extensions Vec2D and Vec3D (ie written in java but loaded as ruby classes at runtime). See:-
https://github.com/jashkenas/ruby-processing/tree/master/ext/processing/vecmath/vec2
https://github.com/jashkenas/ruby-processing/tree/master/ext/processing/vecmath/vec3

When I run rspec with jruby-9.0.0.0-SNAPSHOT (2.2.0p0) 2015-01-24 6a608c2 OpenJDK 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [linux-amd64]. I get the following

Failures:

  1) Vec2D#inspect should return a String
     Failure/Error: expect(a.inspect).to eq 'Vec2D(x = 3.0000, y = 2.0000)'
       
       expected: "Vec2D(x = 3.0000, y = 2.0000)"
            got: "Vec2D:0x565b064f"
       
       (compared using ==)
     # ./vecmath_spec.rb:242:in `(root)'

  2) Vec3D#inspect should return a String
     Failure/Error: expect(a.inspect).to eq 'Vec3D(x = 3.0000, y = 5.0000, z = 2.0000)'
       
       expected: "Vec3D(x = 3.0000, y = 5.0000, z = 2.0000)"
            got: "Vec3D:0x5ef0d29e"

Actually got: #< wrapped code > inside '' but if I did not edit above you would only see a #
Tests pass with jruby-1.7.18, do I need to explicitly create my own inspect with jruby-9.0.0.0?
PS this issue #1740 is still outstanding @headius

@monkstone
Copy link
Contributor Author

I am guessing here but in jruby-1.7.18 I did not need to explicitly implement inspect for my jruby extension classes (Vec2D and Vec3D), because inspect correctly does alias inspect to_s and returns the expected result. For whatever reason my Vec2D, Vec3D classes with jruby 9000 are seen as being java objects? @headius

@monkstone
Copy link
Contributor Author

    @JRubyMethod(name = {"to_s", "inspect"})

    public IRubyObject to_s(ThreadContext context) {
        return context.getRuntime().newString(String.format("Vec3D(x = %4.4f, y = %4.4f, z = %4.4f)", jx, jy, jz));
    }

This fixes the issue for the Vec3D class, but I am asking the question:-
Is the changed behaviour a design change or did it happen by accident?
Further if the change is desired/required there should be some documentation...
@headius

@monkstone
Copy link
Contributor Author

@headius In case it was accidental I've created a minimal test (to reproduce the issue) https://github.com/ruby-processing/extension-inspect

clone the repo then rake to compile the extension class and run test. See README.md

@kares kares added this to the Invalid or Duplicate milestone Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants