Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/nwn/yaml.rb,
lib/nwn/yaml.rb
Instance Attribute Summary collapse
-
#to_yaml_style ⇒ Object
Returns the value of attribute to_yaml_style.
Instance Method Summary collapse
-
#to_yaml(opts = {}) ⇒ Object
Replacing the to_yaml function so it’ll serialize hashes sorted (by their keys) Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb.
Instance Attribute Details
#to_yaml_style ⇒ Object
Returns the value of attribute to_yaml_style.
12 13 14 |
# File 'lib/nwn/yaml.rb', line 12 def to_yaml_style @to_yaml_style end |
Instance Method Details
#to_yaml(opts = {}) ⇒ Object
Replacing the to_yaml function so it’ll serialize hashes sorted (by their keys) Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nwn/yaml.rb', line 18 def to_yaml(opts = {}) YAML::quick_emit(nil, opts) do |out| out.map(taguri, to_yaml_style) do |map| if keys.map {|v| v.class }.size > 0 each do |k, v| map.add(k, v) end else sort.each do |k, v| map.add(k, v) end end end end end |