2006-04-30 16:36:37 -04:00
|
|
|
# OrderedHash is namespaced to prevent conflicts with other implementations
|
2006-05-31 18:43:53 -04:00
|
|
|
module ActiveSupport
|
|
|
|
class OrderedHash < Array #:nodoc:
|
|
|
|
def []=(key, value)
|
2006-08-25 02:01:02 -04:00
|
|
|
if pair = assoc(key)
|
2006-05-31 18:43:53 -04:00
|
|
|
pair.pop
|
|
|
|
pair << value
|
|
|
|
else
|
|
|
|
self << [key, value]
|
|
|
|
end
|
2005-09-30 02:51:42 -04:00
|
|
|
end
|
|
|
|
|
2006-05-31 18:43:53 -04:00
|
|
|
def [](key)
|
2006-08-25 02:01:02 -04:00
|
|
|
pair = assoc(key)
|
2006-05-31 18:43:53 -04:00
|
|
|
pair ? pair.last : nil
|
|
|
|
end
|
2005-09-30 03:14:37 -04:00
|
|
|
|
2006-05-31 18:43:53 -04:00
|
|
|
def keys
|
2006-06-02 13:28:15 -04:00
|
|
|
collect { |key, value| key }
|
|
|
|
end
|
|
|
|
|
|
|
|
def values
|
|
|
|
collect { |key, value| value }
|
2005-09-30 02:51:42 -04:00
|
|
|
end
|
2006-05-31 18:43:53 -04:00
|
|
|
end
|
2006-02-25 18:06:04 -05:00
|
|
|
end
|
|
|
|
|
2006-04-30 16:36:37 -04:00
|
|
|
class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
|
2006-02-25 18:06:04 -05:00
|
|
|
def []=(key, value)
|
|
|
|
super(key.to_sym, value)
|
|
|
|
end
|
2006-05-31 18:43:53 -04:00
|
|
|
|
2006-02-25 18:06:04 -05:00
|
|
|
def [](key)
|
|
|
|
super(key.to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(name, *args)
|
|
|
|
if name.to_s =~ /(.*)=$/
|
|
|
|
self[$1.to_sym] = args.first
|
|
|
|
else
|
|
|
|
self[name]
|
|
|
|
end
|
|
|
|
end
|
2006-05-31 18:43:53 -04:00
|
|
|
end
|