Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/pleasant_path/json/object.rb,
lib/pleasant_path/yaml/object.rb
Instance Method Summary collapse
-
#write_to_json(file, options = {}) ⇒ self
Dumps the Object as JSON, and writes the JSON to the specified file.
-
#write_to_yaml(file, options = {}) ⇒ self
Dumps the Object as YAML, and writes the YAML to the specified file.
Instance Method Details
#write_to_json(file, options = {}) ⇒ self
Dumps the Object as JSON, and writes the JSON to the specified file. Returns the Object unmodified.
For information about available options see JSON.generate.
17 18 19 20 21 22 23 24 25 |
# File 'lib/pleasant_path/json/object.rb', line 17 def write_to_json(file, = {}) = { quirks_mode: true, allow_nan: true, }.merge() file.to_pathname.write_text(JSON.generate(self, )) self end |
#write_to_yaml(file, options = {}) ⇒ self
Dumps the Object as YAML, and writes the YAML to the specified file. Returns the Object unmodified.
For information about available options see YAML.dump.
17 18 19 20 21 22 |
# File 'lib/pleasant_path/yaml/object.rb', line 17 def write_to_yaml(file, = {}) file.to_pathname.make_dirname.open("w") do |f| YAML.dump(self, f, ) end self end |