diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 9e7dc458b48d1..d142f21d61e19 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 9757054e43b85..5de94c67e0a58 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -53,6 +53,14 @@ def has_value?(v) 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 98a6ad6b26c41..17dffbd624856 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -61,4 +61,16 @@ def test_has_value 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