Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the first of the coming core extensions

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f626aece793eab4a414eeb96a3bb3440e98e05d8 1 parent 7145046
@dhh dhh authored
View
1  activesupport/lib/core_ext.rb
@@ -0,0 +1 @@
+Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each { |file| require(file) }
View
6 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
View
14 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
Please sign in to comment.
Something went wrong with that request. Please try again.