module HashConf def self.parse(str) hash = {} str.gsub(/(.*?)\s*{(.*?)}/m) { temp = {} hash[$1.strip] = temp $2.gsub(/([^=]+)\s*=\s*(.*?)(?:,|$)/) { temp[$1.strip] = $2.strip } } return hash end end if $0 == __FILE__ str = %!section_one { foo = bar, bar = baz } section_two { baz = foopy, foopy = noopy } section_three { noopy = loopy }! p HashConf.parse(str) end