diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-27 11:07:07 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-27 11:07:07 +0100 |
commit | 418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2 (patch) | |
tree | 33d51b954b8f6cac5e64e64d2152d6b0ca8cc40c /activesupport/lib/active_support/core_ext/array/extract_options.rb | |
parent | 0cb3311d06c02649fb7444c34b6fdf2214ab85f5 (diff) | |
parent | a24a888afe5652e391ce2ea682596686af5ec58b (diff) | |
download | rails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.tar.gz rails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.tar.bz2 rails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.zip |
Merge branch 'master' of gitproxy:rails/rails
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/extract_options.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/extract_options.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/extract_options.rb b/activesupport/lib/active_support/core_ext/array/extract_options.rb index 9ca32dc7aa..40ceb3eb9e 100644 --- a/activesupport/lib/active_support/core_ext/array/extract_options.rb +++ b/activesupport/lib/active_support/core_ext/array/extract_options.rb @@ -1,3 +1,14 @@ +class Hash + # By default, only instances of Hash itself are extractable. + # Subclasses of Hash may implement this method and return + # true to declare themselves as extractable. If a Hash + # is extractable, Array#extract_options! pops it from + # the Array when it is the last element of the Array. + def extractable_options? + instance_of?(Hash) + end +end + class Array # Extracts options from a set of arguments. Removes and returns the last # element in the array if it's a hash, otherwise returns a blank hash. @@ -9,6 +20,10 @@ class Array # options(1, 2) # => {} # options(1, 2, :a => :b) # => {:a=>:b} def extract_options! - last.is_a?(::Hash) ? pop : {} + if last.is_a?(Hash) && last.extractable_options? + pop + else + {} + end end end |