Skip to content

Instantly share code, notes, and snippets.

@theotherzach
Created March 6, 2013 02:08
Show Gist options
  • Save theotherzach/5096173 to your computer and use it in GitHub Desktop.
Save theotherzach/5096173 to your computer and use it in GitHub Desktop.
config = YAML.load_file(path)
# => {"ip" => "0.0.0.0", "port" => "3000"}
# each_with_object for 1.9+
config.each_with_object({}) { |(k,v),memo| memo[k.to_sym] = v }
# => {:ip=>"0.0.0.0", :port=>"3000"}
# inject for 1.8
config.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
# => {:ip=>"0.0.0.0", :port=>"3000"}
require 'active_support/hash_with_indifferent_access'
# active support
config.symbolize_keys
# => {:ip=>"0.0.0.0", :port=>"3000"}
# in place
config.symbolize_keys!
# => {:ip=>"0.0.0.0", :port=>"3000"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment