Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/nwn/yaml_support.rb,
lib/nwn/yaml_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#to_yaml_styleObject

Returns the value of attribute to_yaml_style.



26
27
28
# File 'lib/nwn/yaml_support.rb', line 26

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nwn/yaml_support.rb', line 32

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