From: Gregory Brown Date: 2009-05-29T02:50:24+09:00 Subject: [ruby-core:23593] Defining #name= at the class level Hi folks, I'd like to just confirm from Matz or one of the core Ruby folks that defining #name at the class level should be an undefined behavior. Almost every implementation I've tried allows the following code to work (MRI, YARV, JRuby, MacRuby): >> @class = Class.new => # >> @class.instance_eval { class << self; attr_accessor :name; end } => nil >> @class.name = "My Special Class" => "My Special Class" >> @class.name => "My Special Class However, Rubinius fails, like this: >> @class = Class.new => # >> @class.instance_eval { class << self; attr_accessor :name; end } => nil >> @class.name = "Foo" TypeError: Tried to use object of type String (48) as type Symbol (49) from Object# (__eval__) at (irb):3 Although this may seem esoteric, I ran into the issue because the test/spec library uses this to assign human names to anonymous classes created in unit tests. I am curious whether this behavior should be considered: 1) Defined to work as MRI and YARV, in which case Rubinius would not be compatible for this feature 2) Undefined, in which case, test/spec should be patched to not use #name=, as it cannot reliably work across implementations 3) Forbidden. In this case, it'd be nice to see the other implementations fail as Rubinius does. I am guessing this is undefined behavior, no different from changing the way any other existing Ruby code works via monkeypatching. If that's the case, I'll just patch test/spec and go away happy. However, if it's one of the other options, I'd like to know. -greg -- BOOK: http://rubybestpractices.com TECH: http://blog.majesticseacreature.com NON-TECH: http://metametta.blogspot.com