Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/nix/convert.rb

Instance Method Summary collapse

Instance Method Details

#to_nix(indent = 0) ⇒ Object


18
19
20
21
22
23
24
25
26
# File 'lib/nix/convert.rb', line 18

def to_nix(indent = 0)
  "{\n" +
  sort {|a, b| a[0].to_s <=> b[0].to_s}.map do |key, value|
    raise "Key must be a Symbol, not #{key.class}" unless key.is_a?(Symbol)
    Nix::INDENT_STRING * (indent + 1)+ key.to_nix +
        " = " + value.to_nix(indent + 1) + ";"
  end.join("\n") + "\n" +
  Nix::INDENT_STRING * indent + "}"
end