# YAML and class variables

**URL:** <https://www.ruby-forum.com/t/yaml-and-class-variables/81055>\
**Category:** Ruby\
**Created:** [January 3, 2007, 12:22pm UTC](https://www.ruby-forum.com/t/yaml-and-class-variables/81055 "2007-01-03T12:22:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@kly](https://www.ruby-forum.com/u/kly)\
**Post date:** [January 3, 2007, 12:22pm UTC](https://www.ruby-forum.com/t/yaml-and-class-variables/81055/1 "2007-01-03T12:22:53Z")

</div>

Hi

When an object’s .to\_yaml method is used, class variables aren’t  
recorded. This makes sense, I guess, but how can someone then serialize  
a class variable and restore it later?

Thanks!  
kLy

---

<div class="post-metadata">

**Author:** ![kly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@kly](https://www.ruby-forum.com/u/kly)\
**Post date:** [January 3, 2007, 12:56pm UTC](https://www.ruby-forum.com/t/yaml-and-class-variables/81055/2 "2007-01-03T12:56:05Z")

</div>

On 03.01.2007 12:22, Rick A. wrote:

> When an object’s .to\_yaml method is used, class variables aren’t  
> recorded. This makes sense, I guess, but how can someone then serialize  
> a class variable and restore it later?

You don’t. Basically a class variable belongs to the class and that’s  
typically not created via some serialization mechanism (yaml, marshal)  
but through code. Apart from that class variables have a whole bunch of  
problems of their own so you better avoid them anyway. My 0.02 EUR…

Kind regards

```
robert
```
