Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (46 sloc) 1.016 kb
7269842 @jeremy Explicit dependency on OrderedHash
jeremy authored
1 require 'active_support/ordered_hash'
2
cdbc880 @neerajdotname adding documentation for OrderedHash and OrderedOptions
neerajdotname authored
3 # Usually key value pairs are handled something like this:
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -exec ...
spastorino authored
4 #
cdbc880 @neerajdotname adding documentation for OrderedHash and OrderedOptions
neerajdotname authored
5 # h = ActiveSupport::OrderedOptions.new
6 # h[:boy] = 'John'
7 # h[:girl] = 'Mary'
e0a0638 @fxn commit review: say clearly that AS::OrderedHash is about insertion order...
fxn authored
8 # h[:boy] # => 'John'
9 # h[:girl] # => 'Mary'
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -exec ...
spastorino authored
10 #
cdbc880 @neerajdotname adding documentation for OrderedHash and OrderedOptions
neerajdotname authored
11 # Using <tt>OrderedOptions</tt> above code could be reduced to:
12 #
13 # h = ActiveSupport::OrderedOptions.new
14 # h.boy = 'John'
15 # h.girl = 'Mary'
e0a0638 @fxn commit review: say clearly that AS::OrderedHash is about insertion order...
fxn authored
16 # h.boy # => 'John'
17 # h.girl # => 'Mary'
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -exec ...
spastorino authored
18 #
c08547d @josh Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under Ac...
josh authored
19 module ActiveSupport #:nodoc:
7269842 @jeremy Explicit dependency on OrderedHash
jeremy authored
20 class OrderedOptions < OrderedHash
c08547d @josh Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under Ac...
josh authored
21 def []=(key, value)
22 super(key.to_sym, value)
23 end
d31830c @jeremy fix test warnings
jeremy authored
24
c08547d @josh Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under Ac...
josh authored
25 def [](key)
26 super(key.to_sym)
27 end
99307b9 @dhh Added calculations: Base.count, Base.average, Base.sum, Base.minimum, Ba...
dhh authored
28
c08547d @josh Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under Ac...
josh authored
29 def method_missing(name, *args)
30 if name.to_s =~ /(.*)=$/
31 self[$1.to_sym] = args.first
32 else
33 self[name]
34 end
99307b9 @dhh Added calculations: Base.count, Base.average, Base.sum, Base.minimum, Ba...
dhh authored
35 end
36 end
6640903 Move InheritableOptions into ActiveSupport
Carlhuda authored
37
38 class InheritableOptions < OrderedOptions
8cda132 @thedarkone Make InheritableOptions's constructor more flexible.
thedarkone authored
39 def initialize(parent = nil)
40 if parent
41 super() { |h,k| parent[k] }
42 else
43 super()
44 end
6640903 Move InheritableOptions into ActiveSupport
Carlhuda authored
45 end
918dc27 @thedarkone Compile ActionController::Base.config's methods to avoid method_missing ...
thedarkone authored
46
47 def inheritable_copy
48 self.class.new(self)
49 end
6640903 Move InheritableOptions into ActiveSupport
Carlhuda authored
50 end
d31830c @jeremy fix test warnings
jeremy authored
51 end
Something went wrong with that request. Please try again.