[ruby-core:55155] [ruby-trunk - misc #8447][Open] BasicObject id behaviour

1 view
Skip to first unread message

kyrylo (Kyrylo Silin)

unread,
May 24, 2013, 11:05:11 AM5/24/13
to ruby...@ruby-lang.org

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/

nobu (Nobuyoshi Nakada)

unread,
May 24, 2013, 9:21:05 PM5/24/13
to ruby...@ruby-lang.org

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

nobu (Nobuyoshi Nakada)

unread,
May 24, 2013, 9:27:42 PM5/24/13
to ruby...@ruby-lang.org

Issue #8447 has been updated by nobu (Nobuyoshi Nakada).


nobu (Nobu4bb9d34yoshi Nakada) wrote:
> It's just an implementation detail, 0x9773a68 == 0x4bb9d34.

Sorry, missent.
"0x9773a68 == 0x4bb9d34<<1", of course.
----------------------------------------
misc #8447: BasicObject id behaviour
https://bugs.ruby-lang.org/issues/8447#change-39525

Author: kyrylo (Kyrylo Silin)
Status: Closed
Reply all
Reply to author
Forward
0 new messages