diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-02 15:16:59 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-02 15:16:59 +0000 |
commit | f4b721904a26f631fbc6d7241b7f9480cc87ea47 (patch) | |
tree | 17c00d0e07848e22a0ba270a93c680cff8a4faf9 /activesupport/lib | |
parent | 089ef42520968c7852c97faf07e5101685885150 (diff) | |
download | rails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.tar.gz rails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.tar.bz2 rails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.zip |
Added test cases and rakefile to Active Support
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@310 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/misc.rb | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/activesupport/lib/misc.rb b/activesupport/lib/misc.rb index db842f6061..d2c3d4a045 100644 --- a/activesupport/lib/misc.rb +++ b/activesupport/lib/misc.rb @@ -1,6 +1,32 @@ def silence_warnings old_verbose, $VERBOSE = $VERBOSE, nil - result = yield - $VERBOSE = old_verbose - return result + 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 |