Issue #8447 has been reported by kyrylo (Kyrylo Silin).
----------------------------------------
misc #8447: BasicObject id behaviour
https://bugs.ruby-lang.org/issues/8447
Author: kyrylo (Kyrylo Silin)
Status: Open
Priority: Low
Assignee: nobu (Nobuyoshi Nakada)
Category: misc
Target version:
=begin
This is not really an issue. This is rather a question. It's about ids of BasicObject instances. When I invoke an undefined method on a BasicObject instance, I get an odd NoMethodError. The message of this error informs me that an undefined method is undefined on some other BasicObject (it has a different id). The code demonstrates the problem better.
b = BasicObject.new
eig = class << b; self; end
puts "A BasicObject's id: #{ b.__id__.to_s(16) }"
puts "Eigenclass' id: #{ eig.__id__.to_s(16) }"
puts "Eigenclass' inspect: #{ eig.inspect }"
begin
b.piyo
rescue => e
puts e
end
Output.
A BasicObject's id: 4e1d918
Eigenclass' id: 4e1d90e
Eigenclass' inspect: #<Class:#<BasicObject:0x9c3b230>>
undefined method `piyo' for #<BasicObject:0x9c3b230>
This is how it looks in a REPL. The ids are different.
irb(main):001:0> b = BasicObject.new
(Object doesn't support #inspect)
=>
irb(main):002:0> b.__id__.to_s(16)
=> "4bb9d34"
irb(main):003:0> b.piyo
NoMethodError: undefined method `piyo' for #<BasicObject:0x9773a68>
from (irb):3
from /opt/rubies/ruby-1.9.3-p392/bin/irb:12:in `<main>'
irb(main):004:0>
I tested this against Ruby 1.9.3, Ruby 2.0.0. I guess this is by design, because I got the same result on JRuby. So I'm just curious, what happens here?
=end
--
http://bugs.ruby-lang.org/