From 9984266c041e1079a09140f9307fc1ca13858988 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sat, 3 Sep 2011 14:43:33 +0700 Subject: Make `ActiveSupport::OrderedHash` extractable when using `Array#extract_options!` `ActiveSupport::OrderedHash` is actually a subclass of the hash, so it does make sense that it should be extractable from the array list. --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/ordered_hash.rb | 5 +++++ activesupport/test/ordered_hash_test.rb | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 3508ec0f34..18164234a5 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* ActiveSupport::OrderedHash is now marked as extractable when using Array#extract_options! [Prem Sichanugrist] + * Added Array#prepend as an alias for Array#unshift and Array#append as an alias for Array#<< [DHH] * The definition of blank string for Ruby 1.9 has been extended to Unicode whitespace. diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 7f70628933..0264133581 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -47,6 +47,11 @@ module ActiveSupport self end + # Returns true to make sure that this hash is extractable via Array#extract_options! + def extractable_options? + true + end + # Hash is ordered in Ruby 1.9! if RUBY_VERSION < '1.9' diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index bf851dbcbc..0b5f912dc4 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -329,4 +329,9 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal expected, @ordered_hash.invert assert_equal @values.zip(@keys), @ordered_hash.invert.to_a end + + def test_extractable + @ordered_hash[:rails] = "snowman" + assert_equal @ordered_hash, [1, 2, @ordered_hash].extract_options! + end end -- cgit v1.2.3