From: Daniel Berger Date: 2005-11-22T04:33:22+09:00 Subject: Re: Problem with Pickaxe and Yaml 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 = valuable > @volatile = volatile > @precious = precious > end > > def to_yaml_properties > %w{@precious @valuable} > end > > def to_s > "#@valuable #@volatile #@precious" > end > end > > obj = Special.new("Hello", "there", "world") > data = YAML.dump(obj) > obj = YAML.load(data) > puts obj["valuable"] > > The last line throws an error, shouldn't it print out the value for > "valuable"? No. There's no "[]" method defined. Try 'puts obj'. That line isn't in the example, btw. Regards, Dan