diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-30 06:51:42 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-30 06:51:42 +0000 |
commit | 9f146ea0ac904252b16be1c4017604aed0c383f7 (patch) | |
tree | 3df5a66f95796d53ecedc982b56e7f50edc55f12 /activesupport/lib | |
parent | 3f1aad8ac958419c11703140e697a4dfc245b161 (diff) | |
download | rails-9f146ea0ac904252b16be1c4017604aed0c383f7.tar.gz rails-9f146ea0ac904252b16be1c4017604aed0c383f7.tar.bz2 rails-9f146ea0ac904252b16be1c4017604aed0c383f7.zip |
Added OrderedOptions array/hash for use with initializer
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2419 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/ordered_options.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb new file mode 100644 index 0000000000..3952ba41f2 --- /dev/null +++ b/activesupport/lib/active_support/ordered_options.rb @@ -0,0 +1,23 @@ +class OrderedOptions < Array + def []=(key, value) + key = key.to_sym + + if pair = find_pair(key) + pair.pop + pair << value + else + self << [key, value] + end + end + + def [](key) + pair = find_pair(key.to_sym) + pair ? pair.last : nil + end + + private + def find_pair(key) + self.each { |i| return i if i.first == key } + return false + end +end
\ No newline at end of file |