aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-05-12 16:13:00 -0300
committerEmilio Tagua <miloops@gmail.com>2009-05-12 16:13:00 -0300
commit0048897a417774f7e5a0c8c9e82fc8684f94ebc1 (patch)
tree8df248dab434bdaac61ea60249d4630958260eed /activesupport/lib/active_support/ordered_hash.rb
parent6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5 (diff)
parent22c5667c2ef46d6723c1805d3adc52dc8e92429b (diff)
downloadrails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.tar.gz
rails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.tar.bz2
rails-0048897a417774f7e5a0c8c9e82fc8684f94ebc1.zip
Merge commit 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index fed8094a24..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
@@ -57,6 +67,10 @@ module ActiveSupport
self
end
+ def to_a
+ @keys.map { |key| [ key, self[key] ] }
+ end
+
def each_key
@keys.each { |key| yield key }
end