# Rb\_cv\_set defines class var but doesn't?

**URL:** <https://www.ruby-forum.com/t/rb-cv-set-defines-class-var-but-doesnt/133115>\
**Category:** Ruby\
**Created:** [March 28, 2008, 12:25am UTC](https://www.ruby-forum.com/t/rb-cv-set-defines-class-var-but-doesnt/133115 "2008-03-28T00:25:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [March 28, 2008, 12:25am UTC](https://www.ruby-forum.com/t/rb-cv-set-defines-class-var-but-doesnt/133115/1 "2008-03-28T00:25:06Z")

</div>

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?
