Skip to content

Instantly share code, notes, and snippets.

@yasaichi
Created March 13, 2015 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasaichi/a552091afa33c5346c22 to your computer and use it in GitHub Desktop.
Save yasaichi/a552091afa33c5346c22 to your computer and use it in GitHub Desktop.
rails/rails/blob/4-2-stable/activesupport/lib/active_support/core_ext/hash/keys.rb
class Hash
def transform_keys
return enum_for(:transform_keys) unless block_given?
result = self.class.new
each_key do |key|
result[yield(key)] = self[key]
end
result
end
def symbolize_keys
transform_keys{ |key| key.to_sym rescue key }
end
alias_method :to_options, :symbolize_keys
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment