diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-09 15:00:45 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-09 15:00:45 +0000 |
commit | f626aece793eab4a414eeb96a3bb3440e98e05d8 (patch) | |
tree | 25a8e98ca0f38a9570abc1a7aa3518af7822c807 /activesupport | |
parent | 7145046493f122f26717149dcb03b8a1689b5c76 (diff) | |
download | rails-f626aece793eab4a414eeb96a3bb3440e98e05d8.tar.gz rails-f626aece793eab4a414eeb96a3bb3440e98e05d8.tar.bz2 rails-f626aece793eab4a414eeb96a3bb3440e98e05d8.zip |
Added the first of the coming core extensions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/core_ext.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/core_ext/hash_ext.rb | 6 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 14 |
3 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/lib/core_ext.rb b/activesupport/lib/core_ext.rb new file mode 100644 index 0000000000..d288fb7e31 --- /dev/null +++ b/activesupport/lib/core_ext.rb @@ -0,0 +1 @@ +Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each { |file| require(file) }
\ No newline at end of file diff --git a/activesupport/lib/core_ext/hash_ext.rb b/activesupport/lib/core_ext/hash_ext.rb new file mode 100644 index 0000000000..90670c42c7 --- /dev/null +++ b/activesupport/lib/core_ext/hash_ext.rb @@ -0,0 +1,6 @@ +class Hash + def assert_valid_keys(valid_keys) + unknown_keys = keys - valid_keys + raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? + end +end
\ No newline at end of file diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb new file mode 100644 index 0000000000..f481cf0242 --- /dev/null +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -0,0 +1,14 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/core_ext/hash_ext' + +class HashExtTest < Test::Unit::TestCase + def test_assert_valid_keys + assert_nothing_raised do + { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + end + + assert_raises(ArgumentError, "Unknown key(s): failore") do + { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + end + end +end
\ No newline at end of file |