diff options
Diffstat (limited to 'activesupport/lib/active_support')
-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 |