From: Jeff Wood Date: 2005-11-22T04:40:27+09:00 Subject: Re: Problem with Pickaxe and Yaml ------=_Part_39124_5094103.1132602022150 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Uh ... your code is *NOT* precisely the example. There's nothing in the original example that does a ["valuable"] call to either the original or th= e reloaded objects. puts "Before: #{ obj }" data =3D Marshal.dump( obj ) obj =3D Marshal.load( data ) puts "After: #{ obj }" Which uses the #to_s function to get access to the internal variables. If you do the same, you should see the output that they show on p417. If you aren't going to quote the source verbatim, you probably should expec= t the exact same output. Anyways, hope that helps. j. On 11/21/05, Mark Haliday wrote: > > I've got the Pickaxe book (2nd edition) and was doing some of the Yaml > code on page 417. I cannot seem to get the expected results. > > Example: > > require 'yaml' > > class Special > > def initialize(valuable, volatile, precious) > @valuable =3D valuable > @volatile =3D volatile > @precious =3D precious > end > > def to_yaml_properties > %w{@precious @valuable} > end > > def to_s > "#@valuable #@volatile #@precious" > end > end > > obj =3D Special.new("Hello", "there", "world") > data =3D YAML.dump(obj) > obj =3D YAML.load(data) > > puts obj["valuable"] > > The last line throws an error, shouldn't it print out the value for > "valuable"? > > I also tried this for the last line: > > puts data["valuable"] > > Thanks for any help on this. > > -- > Posted via http://www.ruby-forum.com/. > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_39124_5094103.1132602022150--