Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > YAML and X < Hash

Thread Tools

YAML and X < Hash

Matt Mower
Posts: n/a
Hi folks.

Porting some Python code to Ruby I have come across an issue in the
YAML module. The Python code uses a Dict subclass which I translated
into a Hash subclass in my Ruby code.

When I use YAML to store my Hash subclass instances none of the
instance variables are stored, only the hashed pairs. This seems to
be the case for Hash and any subclasses of Hash, e.g.

class Y < Hash
attr_accessor :value

def initialize( value )
@value = value

y = "test" )
puts y.to_yaml


--- !ruby/hash:Y {}

I converted my code to use a Hash by composition rather than
inheritance which avoids the loss of the instance variables in the
subclass. However the default value for the Hash is an instance
variable and is also lost.



Matt Mower ::

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
yaml.rb and YAML "%" directives Joshua Choi Ruby 1 01-14-2007 07:53 AM
Puzzling over why ri can open the std ruby/ri .yaml files, but raw yaml can't Eric Promislow Ruby 4 10-31-2006 10:15 PM
YAML.dump/YAML.load bug Paul Battley Ruby 0 08-03-2005 08:28 PM
YAML Question: Using YAML::YamlNode#transform Method to get float values? RubyQuestions Ruby 0 12-03-2003 02:15 AM