[ruby-core:68847] [Ruby trunk - Bug #11059] [Open] When saving a hash to YAML or JSON the default value isn't stored

From: kisbelus@...
Date: 2015-04-11 09:50:15 UTC
List: ruby-core #68847
Issue #11059 has been reported by Orosz Szilard.

----------------------------------------
Bug #11059: When saving a hash to YAML or JSON the default value isn't stored
https://bugs.ruby-lang.org/issues/11059

* Author: Orosz Szilard
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [i686-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I tried to serialize/save a hash to a YAML file, with YAML.dump. My hash has a default value set in. When I read the hash back with YAML.load, the default value is lost, because it wasn1t stored in the YAML file. I experienced the same issue using JSON.

~~~
require "yaml"
hash={"a"=>0.3,"b"=>0.7}
hash.default=1.0
File.write("hash.yaml",YAML.dump(hash))
hash2=YAML.load(File.read("hash.yaml"))
puts hash2.default
=> nil
~~~




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next