Sha256: de790af4e622f1f169fade2f2259e40c4afb977ad2708814eefef4a629fa6f9b
Contents?: true
Size: 971 Bytes
Versions: 1
Compression:
Stored size: 971 Bytes
Contents
class Object # Writes the Object serialized as JSON to the specified +file+, # overwriting the file if it exists. Creates the file if it does not # exist, including any necessary parent directories. Returns the # Object, unmodified. # # For information about +options+ see # {https://docs.ruby-lang.org/en/trunk/JSON.html#method-i-generate # +JSON.generate+}. By default, this method uses # {https://docs.ruby-lang.org/en/trunk/JSON.html#attribute-c-dump_default_options # +JSON.dump_default_options+}. # # @example # { "key" => "value" }.write_to_json("out.json") # == { "key" => "value" } # File.read("out.json") # == '{"key":"value"}' # # @param file [String, Pathname] # @param options [Hash<Symbol, Object>] # @return [self] def write_to_json(file, options = {}) options = JSON.dump_default_options.merge(options) file.to_pathname.write_text(self.to_json(options)) self end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pleasant_path-1.3.0 | lib/pleasant_path/json/object.rb |