require 'set' class Set def push(*args) send(:<<, *args) end end class Hash def to_mash Hashie::Mash.new(self) end def lookup_path dot_separated_path, create=false parts = dot_separated_path.to_s.split('.') parts.reduce(self) do |memo, part| memo && memo[part.to_sym] ||= memo[part.to_s] || (create if create) end end def make_path dot_separated_path, blank_value, overwrite=false dot_separated_path = dot_separated_path.to_s existing = lookup_path(dot_separated_path) return existing if existing && !overwrite parts = dot_separated_path.split(".") current = self if parts.length == 1 return self[parts.first] ||= blank_value end key = parts.pop parts.each do |part| current = current[part.to_sym] = current.delete(part.to_s) || {} end current[key.to_sym] = blank_value lookup_path(dot_separated_path, false) end end class Pathname def to_pathname self end end class String def to_pathname Pathname(self) end end