aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorchaitanyav <me@chaitanyavellanki.com>2010-06-26 01:52:20 -0700
committerJosé Valim <jose.valim@gmail.com>2010-06-26 12:05:25 +0200
commit9958950f78638e4a6c6800404d84f22effc0748e (patch)
treea1c96fd8cae120ae64f68eaf916ba7f424be7460 /activesupport/lib
parentd4e1a2ef0d35f322803284a980575fc31ff7b4b6 (diff)
downloadrails-9958950f78638e4a6c6800404d84f22effc0748e.tar.gz
rails-9958950f78638e4a6c6800404d84f22effc0748e.tar.bz2
rails-9958950f78638e4a6c6800404d84f22effc0748e.zip
Add OrderedHash#invert to preserve order in ruby 1.8 [#4875]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index a19d6c3532..6b563b9063 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -162,6 +162,10 @@ module ActiveSupport
self
end
+ def invert
+ OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
+ end
+
def inspect
"#<OrderedHash #{super}>"
end