Module: Murlsh::YamlOrderedHash

Defined in:
lib/murlsh/yaml_ordered_hash.rb

Overview

Hash mixin to generate yaml with hash keys in sorted order.

Instance Method Summary collapse

Instance Method Details

#to_yaml(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/murlsh/yaml_ordered_hash.rb', line 8

def to_yaml(opts={})
  YAML::quick_emit(self, opts) do |out|
    out.map(taguri, to_yaml_style) do |map|
      sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |k, v|
        map.add k, v
      end
    end
  end
end