From: "nobu (Nobuyoshi Nakada)" Date: 2013-05-25T10:21:05+09:00 Subject: [ruby-core:55159] [ruby-trunk - misc #8447][Closed] BasicObject id behaviour Issue #8447 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Closed It's just an implementation detail, 0x9773a68 == 0x4bb9d34. ---------------------------------------- misc #8447: BasicObject id behaviour https://bugs.ruby-lang.org/issues/8447#change-39524 Author: kyrylo (Kyrylo Silin) Status: Closed 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: #> undefined method `piyo' for # 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 # from (irb):3 from /opt/rubies/ruby-1.9.3-p392/bin/irb:12:in `
' 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/