From: Anders Borch Date: 2003-04-27T23:14:42+09:00 Subject: Re: How to undefine a member variable ? (or at least hide it from YAML) Simon Vandemoortele wrote: > I came across the following problem while using YAML: > > #+v > require "yaml" > > class A > attr_writer :s > end > > a = A.new > > puts (a.s ="something").to_yaml > => "--- !ruby/object:A \na: something" > > puts (a.s = nil).to_yaml > "--- !ruby/object:A \na: > #-v > > My problem, as you can see, is that: > 1) once I've assigned to a member variable there is (to my knowledge) no > way to 'undefine' it > 2) YAML dumps all defined variables > > This means that, over time, my object dumps will become more and more > cluttered with empty entries. I am sure YAML experts have run into that > problem and have a lot to say about it ... > > As I see it: either I find a way to 'undefine' a variable, or I find a way > to tell YAML *not* to dump nil values. (I prefer the latter of course.) > > > Simon > If you have a lot of values that come and go, then why not put them in a hash? that should make sure you do not clutter your namespace... /Anders