Class: Array

Inherits:
Object show all
Defined in:
lib/toml/monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#to_toml(path = "") ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/toml/monkey_patch.rb', line 56

def to_toml(path = "")
  unless self.map(&:class).uniq.length == 1
    raise "All array values must be the same type"
  end

  if self.first.toml_table?
    toml = ""
    self.each do |val|
      toml << "\n[[#{path}]]\n"
      toml << val.to_toml(path)
    end
    return toml
  else
    "[" + self.map {|v| v.to_toml(path) }.join(",") + "]"
  end
end