Quick Tip: Parsing a Config String in Ruby

Recently I came across the need to parse a bit of a config file, in this kind of format: “Category=filetype;…” Here is how one would do such a thing using <a title="Docs for the string split method" href="http://ruby-doc.org/core-2.2.1/String.html#method-i-split” target=”_blank”>split, inject and map.

The result is a hash where you can get an array of the file extensions for a given category like this

and the resulting hash looks like this:

Let me know in the comments if you have a better way!


No Comments

A name is required.
An email is required.
Invalid URL

No comments yet