1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update duplicated OrderedOptions code.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3664 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Nicholas Seckar 2006-02-26 01:56:09 +00:00
parent 647130d7ff
commit 55bb615f10

View file

@ -569,10 +569,8 @@ end
# Needs to be duplicated from Active Support since its needed before Active
# Support is available.
class OrderedOptions < Array # :nodoc:
def []=(key, value)
key = key.to_sym
class OrderedHash < Array #:nodoc:
def []=(key, value)
if pair = find_pair(key)
pair.pop
pair << value
@ -580,12 +578,32 @@ class OrderedOptions < Array # :nodoc:
self << [key, value]
end
end
def [](key)
pair = find_pair(key.to_sym)
pair = find_pair(key)
pair ? pair.last : nil
end
def keys
self.collect { |i| i.first }
end
private
def find_pair(key)
self.each { |i| return i if i.first == key }
return false
end
end
class OrderedOptions < OrderedHash #:nodoc:
def []=(key, value)
super(key.to_sym, value)
end
def [](key)
super(key.to_sym)
end
def method_missing(name, *args)
if name.to_s =~ /(.*)=$/
self[$1.to_sym] = args.first
@ -593,10 +611,4 @@ class OrderedOptions < Array # :nodoc:
self[name]
end
end
private
def find_pair(key)
self.each { |i| return i if i.first == key }
return false
end
end
end