diff options
author | Christoffer Sawicki <christoffer.sawicki@gmail.com> | 2008-11-18 23:00:35 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-11-26 14:54:35 +0100 |
commit | 05a938c5f7804fd59c76c45df096e6ebff871a18 (patch) | |
tree | 70872a576afdf06add220d2f59247b30bae2ebc3 | |
parent | 63d8f56774dcb1ea601928c3eb6c119d359fae10 (diff) | |
download | rails-05a938c5f7804fd59c76c45df096e6ebff871a18.tar.gz rails-05a938c5f7804fd59c76c45df096e6ebff871a18.tar.bz2 rails-05a938c5f7804fd59c76c45df096e6ebff871a18.zip |
Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value [#1410 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/ordered_hash.rb | 8 | ||||
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 12 |
3 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 9e7dc458b4..d142f21d61 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *2.3.0 [Edge]* +* Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value #1410 [Christoffer Sawicki] + * Added ActiveSupport::MessageVerifier and MessageEncryptor to aid users who need to store signed and/or encrypted messages. [Koz] * Added ActiveSupport::BacktraceCleaner to cut down on backtrace noise according to filters and silencers [DHH] diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 9757054e43..5de94c67e0 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -53,6 +53,14 @@ module ActiveSupport end alias_method :value?, :has_value? + + def each_key + each { |key, value| yield key } + end + + def each_value + each { |key, value| yield value } + end end end end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 98a6ad6b26..17dffbd624 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -61,4 +61,16 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal false, @ordered_hash.has_value?('ABCABC') assert_equal false, @ordered_hash.value?('ABCABC') end + + def test_each_key + keys = [] + @ordered_hash.each_key { |k| keys << k } + assert_equal @keys, keys + end + + def test_each_value + values = [] + @ordered_hash.each_value { |v| values << v } + assert_equal @values, values + end end |