[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

YAML and X < Hash

Matt Mower

4/10/2005 7:01:00 PM

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
end
end

y = Y.new( "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.

Regards,

Matt

--
Matt Mower :: http://matt...