I would suggest abandon YAML for JSON files.
# Where Opts is a local constant referencing a hash of plugin options
require 'json'
# Write out the options:
opts_json = Opts.to_json
filepath = File.join(__dir__,'options.json')
IO.write(filepath, opts_json)
# Load the options:
filepath = File.join(__dir__,'options.json')
opts_json = IO.read(filepath)
Opts.merge!(JSON.parse(opts_json))
REF: Module: JSON (Ruby 2.7.2)
NOTE: If you want “pretty” readable output .json
files, then use JSON.pretty_generate()
instead of the plain Jane to_json
…
opts_json = JSON.pretty_generate(Opts)
Here is old topic where I posted a set of methods to control options …
Storing Plugin Data Revisited (Wall Presets) - #19 by DanRathbun