Rb_cv_set defines class var but doesn't?

I’m using rb_cv_set in a C extension to set the value of a class
variable. Via gdb I can see that rb_cv_set successfully creates the
variable. The rb_cvar_defined function returns Qtrue and a subsequent
call to rb_cv_get returns the correct value. From the C side, everything
is copacetic.

From Ruby, however, things are squirrely. Using class_eval I can see
the variable:

MyClass.class_eval { p class_variables }

shows ["@@tmpnam"] as expected. However,

MyClass.class_eval { x = @@tmpnam }

raises NameError: “uninitialized class variable @@tmpnam in MyClass”.

MyClass.class_eval { p defined? @@tmpnam }

shows “nil”.

I’m running 1.8.6 patchlevel 114 on Kubuntu Gutsy.

This works as expected with Ruby 1.9.0-1.

Is this just a bug in 1.8.6? Is there another way I can inspect the
value of @@tmpnam in 1.8.6?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs