I'm working on a small command line app project at the moment and I need
to store settings. I decided to use YAML for the first time and a hash,
which is converted into a string which is in YAML, and then save that
into a file. The below is the code for the writing to the file:
read
previous_settings = @result @settings.each do |k, v|
previous_settings[k] = v
end
if File.writable_real?(FILE)
File.open(FILE, 'w+') do |f|
f << previous_settings.to_yaml
end @result = true
else @result = false
end
All it does is it reads the file and sets its contents to the @result
variable. Then the previous_setting variable is set to that and the
contents of the @settings are added onto it. I then simply write to the
file. My question is: how do I delete a setting in a YAML file? Say this
is my YAML file:
And I want to remove the h5bp option? Is there a way of doing that
without actually opening the file, searching through it with Regex, and
then removing the setting and its value? I'm using Ruby 2.0.