From: Quintus Date: 2013-05-12T22:24:45+09:00 Subject: Re: How do I remove a setting from a YAML file? --Sig_/wM0o=EV28pa_5_GZzLnM_j5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Am Sun, 12 May 2013 20:39:37 +0900 schrieb "Rafal C." : Hi Rafal, > File.open(FILE, 'w+') do |f| > f << previous_settings.to_yaml > end Why do you use "w+" as the file mode? You don=E2=80=99t read from the file = in the supplied block. > My question is: how do I delete a setting in a YAML file? > Say this is my YAML file: >=20 > --- > foundation: http://foundation.zurb.com/files/foundation-4.1.6.zip > normalize: http://necolas.github.io/normalize.css/2.1.1/normalize.css > h5bp: https://github.com/h5bp/html5-boilerplate/archive/master.zip > > And I want to remove the h5bp option? Simply load the YAML file, delete the corresponding hash key, and write the file back out to disk. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hsh =3D YAML.load_file("yourfile.yml") hsh.delete("h5bp") File.open("yourfile.yml", "w"){|f| YAML.dump(hsh, f)} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vale, Marvin --=20 Blog: http://pegasus-alpha.eu/blog ASCII-Ribbon-Kampagne () | ASCII Ribbon Campaign () - Stoppt HTML-E-Mail /\ | - Against HTML E-Mail /\ - Stoppt propriet=C3=A4re Anh=C3=A4nge | - Against proprietary attachm= ents www.asciiribbon.org/index-de.html | www.asciiribbon.org --Sig_/wM0o=EV28pa_5_GZzLnM_j5 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQEcBAEBAgAGBQJRj5gWAAoJELh1XLHFkqhaEugIAJTXZ7XxpHPouyyZXuSu1TJl GjcxzfQ1WdzfWHdqGhH8y3/iRiRH3tBNUBaz4qGVq2nUYnX5VcW9HQzyF/nvcgTL PhXKQipZO+ex1cRUtgyPgnCC0TmvJF8Y5KefE0Vb7/iHsqQlQLhEqudGYmKFkKth X2IOZI34V8ukx2uKGszqxH/smA+laMikd74Nx0Mmp+ppggGkSkRVRmk9QbO3HtKa X68Lv63/u2vL2CvXVCPmgF+WQALBPmLtpibY2DApExDX7eHiIO4BLLpqqY8JInWc dCXzjRerky96F8ZLBY6eG+MPDFPgdqKq5T7CTImsT4o3Vt+5cHADc742eqvQ+ks= =lRak -----END PGP SIGNATURE----- --Sig_/wM0o=EV28pa_5_GZzLnM_j5--