mirror of
https://github.com/github/rails.git
synced 2026-02-15 00:25:00 -05:00
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@310 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
33 lines
630 B
Ruby
33 lines
630 B
Ruby
def silence_warnings
|
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
|
begin
|
|
yield
|
|
ensure
|
|
$VERBOSE = old_verbose
|
|
end
|
|
end
|
|
|
|
class Hash
|
|
# Return a new hash with all keys converted to symbols.
|
|
def symbolize_keys
|
|
inject({}) do |options, (key, value)|
|
|
options[key.to_sym] = value
|
|
options
|
|
end
|
|
end
|
|
|
|
# Destructively convert all keys to symbols.
|
|
def symbolize_keys!
|
|
keys.each do |key|
|
|
unless key.is_a?(Symbol)
|
|
self[key.to_sym] = self[key]
|
|
delete(key)
|
|
end
|
|
end
|
|
self
|
|
end
|
|
|
|
alias_method :to_options, :symbolize_keys
|
|
alias_method :to_options!, :symbolize_keys!
|
|
end
|