jm / toml

Parse TOML. Like a bawss.
MIT License
151 stars 38 forks source link

Preserve hash structure when generating a TOML file #70

Open pinecat opened 2 years ago

pinecat commented 2 years ago

For a given hash, preserve its structure when generating the TOML doc string (via TOML::Generator.new(hash).body). To do this, you would pass in a boolean with the constructor for TOML::Generator.

body = Generator.new(doc, false).body # Creates a TOML string that sorts the hash keys of 'doc'
body = Generator.new(doc, true).body # Creates a TOML string which preserves the structure of the the hash, 'doc'

The default value is false, mimicking the current behavior.

body = Generator.new(doc).body # Creates a TOML string that sorts the hash keys of 'doc'

Fixes #69.