aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
authorDouglas F Shearer <dougal.s@gmail.com>2009-05-07 23:58:07 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2009-05-11 11:45:57 -0700
commite1854e0b199fba352ddcaa58a3af168e8cc70e3a (patch)
treef9d528ae07f6ccdb5b469ad35fb2ffbfcf4a5a24 /activesupport/lib/active_support/ordered_hash.rb
parentd45d0a18647e906223b2859d1ce2a83be00095b1 (diff)
downloadrails-e1854e0b199fba352ddcaa58a3af168e8cc70e3a.tar.gz
rails-e1854e0b199fba352ddcaa58a3af168e8cc70e3a.tar.bz2
rails-e1854e0b199fba352ddcaa58a3af168e8cc70e3a.zip
ActiveSupport::OrderedHash[1,2,3,4] creates an OrderedHash instead of a Hash.
[#2615 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 33fd2a29b9..8d1c0f5160 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -10,6 +10,16 @@ module ActiveSupport
@keys = []
end
+ def self.[](*args)
+ ordered_hash = new
+ args.each_with_index { |val,ind|
+ # Only every second value is a key.
+ next if ind % 2 != 0
+ ordered_hash[val] = args[ind + 1]
+ }
+ ordered_hash
+ end
+
def initialize_copy(other)
super
# make a deep copy of keys