M
Mark Haliday
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"?
I also tried this for the last line:
puts data["valuable"]
Thanks for any help on this.
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"?
I also tried this for the last line:
puts data["valuable"]
Thanks for any help on this.