Upgraded Rails and RSpec
[monkeycharger.git] / vendor / rails / activesupport / lib / active_support / ordered_options.rb
blob1542a2479e8be24f9aed11b98b4123fd65fde793
1 # OrderedHash is namespaced to prevent conflicts with other implementations
2 module ActiveSupport
3   # Hash is ordered in Ruby 1.9!
4   if RUBY_VERSION >= '1.9'
5     OrderedHash = ::Hash
6   else
7     class OrderedHash < Array #:nodoc:
8       def []=(key, value)
9         if pair = assoc(key)
10           pair.pop
11           pair << value
12         else
13           self << [key, value]
14         end
15       end
17       def [](key)
18         pair = assoc(key)
19         pair ? pair.last : nil
20       end
22       def keys
23         collect { |key, value| key }
24       end
26       def values
27         collect { |key, value| value }
28       end
29     end
30   end
31 end
33 class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
34   def []=(key, value)
35     super(key.to_sym, value)
36   end
38   def [](key)
39     super(key.to_sym)
40   end
42   def method_missing(name, *args)
43     if name.to_s =~ /(.*)=$/
44       self[$1.to_sym] = args.first
45     else
46       self[name]
47     end
48   end
49 end