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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
YAML and X < Hash
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password