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

String#<< doesn't call to_str on objects when they allege to not respond to it. #1901

Closed
JoshCheek opened this issue Aug 14, 2014 · 2 comments
Milestone

Comments

@JoshCheek
Copy link

The file:

$ cat f.rb
o = Object.new
def o.method_missing(*)
  'abc'
end
p("" << o)

jruby 1.7.12 (1.9.3p392) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_51-b13 [darwin-x86_64]

$ ruby f.rb
TypeError: can't convert Object into String
  concat at org/jruby/RubyString.java:2601
  (root) at f.rb:5

ruby 1.9.3p545 (2014-02-24) [x86_64-darwin13.2.0]

$ ruby f.rb
"abc"

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

$ ruby f.rb
"abc"

If, however, I define respond_to?:

$ ruby -v
jruby 1.7.12 (1.9.3p392) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_51-b13 [darwin-x86_64]

$ cat f.rb
o = Object.new
def o.method_missing(*)
  'abc'
end
def o.respond_to?(*)
  true
end
p("" << o)

$ ruby f.rb
"abc"

Obviously, it's not a great idea to do this, but I think it reality it's pretty common, lots of people define method_missing without defining respond_to, and I'm pretty sure this is what's causing the currently released version of Pry to be unable to show output for whereami and show-source (pry/pry#1284)

@MSNexploder
Copy link
Contributor

This can be closed.
Works under both 9.1.9.0 and 1.7.21 just as expected.

@headius
Copy link
Member

headius commented May 21, 2017

Thank you!

@headius headius closed this as completed May 21, 2017
@headius headius added this to the JRuby 9.1.9.0 milestone May 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants