Module#class_variable_defined? doesn't match the documentation, making it
effectively equivalent to Kernel#instance_variable_defined?:

 class X; @a = 1 end
 X.class_variable_defined? :@a                     # => true
 X.class_variable_defined? :@@a                 
 # ~> in `Module#class_variable_defined?': `@@a' is not allowed as an instance variable name (NameError)

Patch:


Index: object.c =================================================================== RCS file: /src/ruby/object.c,v retrieving revision 1.204 diff -p -u -r1.204 object.c --- object.c 7 Oct 2006 02:53:24 -0000 1.204 +++ object.c 12 Oct 2006 10:42:17 -0000 @@ -1760,8 +1760,8 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv) { ID id = rb_to_id(iv); - if (!rb_is_instance_id(id)) { - rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); + if (!rb_is_class_id(id)) { + rb_name_error(id, "`%s' is not allowed as an class variable name", rb_id2name(id)); } return rb_cvar_defined(obj, id); }
After applying, class X; @@a = 1 end X.class_variable_defined? :@@a # => true X.class_variable_defined? :@@b # => false X.class_variable_defined? :@a # => # ~> -:4:in `Module#class_variable_defined?': `@a' is not allowed as an class variable name (NameError) # ~> from -:4 as expected. -- Mauricio Fernandez - http://eigenclass.org - singular Ruby