Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 47 lines (40 sloc) 0.86 kB
325cb12 @technoweenie Namespaced OrderedHash so the Rails implementation does not clash wit…
technoweenie authored
1 # OrderedHash is namespaced to prevent conflicts with other implementations
d31830c @jeremy fix test warnings
jeremy authored
2 module ActiveSupport
3 class OrderedHash < Array #:nodoc:
4 def []=(key, value)
5 if pair = find_pair(key)
6 pair.pop
7 pair << value
8 else
9 self << [key, value]
10 end
9f146ea @dhh Added OrderedOptions array/hash for use with initializer
dhh authored
11 end
12
d31830c @jeremy fix test warnings
jeremy authored
13 def [](key)
14 pair = find_pair(key)
15 pair ? pair.last : nil
16 end
d994b41 @dhh Added method access to OrdredOptions
dhh authored
17
d31830c @jeremy fix test warnings
jeremy authored
18 def keys
19 self.collect { |i| i.first }
9f146ea @dhh Added OrderedOptions array/hash for use with initializer
dhh authored
20 end
d31830c @jeremy fix test warnings
jeremy authored
21
22 private
23 def find_pair(key)
24 self.each { |i| return i if i.first == key }
25 return false
26 end
27 end
99307b9 @dhh Added calculations: Base.count, Base.average, Base.sum, Base.minimum,…
dhh authored
28 end
29
325cb12 @technoweenie Namespaced OrderedHash so the Rails implementation does not clash wit…
technoweenie authored
30 class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
99307b9 @dhh Added calculations: Base.count, Base.average, Base.sum, Base.minimum,…
dhh authored
31 def []=(key, value)
32 super(key.to_sym, value)
33 end
d31830c @jeremy fix test warnings
jeremy authored
34
99307b9 @dhh Added calculations: Base.count, Base.average, Base.sum, Base.minimum,…
dhh authored
35 def [](key)
36 super(key.to_sym)
37 end
38
39 def method_missing(name, *args)
40 if name.to_s =~ /(.*)=$/
41 self[$1.to_sym] = args.first
42 else
43 self[name]
44 end
45 end
d31830c @jeremy fix test warnings
jeremy authored
46 end
Something went wrong with that request. Please try again.