Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (32 sloc) 0.826 kB
88ecd07 @josevalim Move hash with indifferent access to core extensions.
josevalim authored
1 class Thor
2 module CoreExt
3 class HashWithIndifferentAccess < ::Hash
4 def initialize(hash)
5 super()
6 update hash
7 end
8
9 def [](key)
10 super convert_key(key)
11 end
12
13 def values_at(*indices)
14 indices.collect { |key| self[convert_key(key)] }
15 end
16
17 protected
18 def convert_key(key)
19 key.kind_of?(Symbol) ? key.to_s : key
20 end
21
22 # Magic predicates. For instance:
23 # options.force? # => !!options['force']
24 def method_missing(method, *args, &block)
25 method = method.to_s
26 if method =~ /^(\w+)=$/
27 self[$1] = args.first
28 elsif method =~ /^(\w+)\?$/
29 !!self[$1]
30 else
31 self[method]
32 end
33 end
34 end
35 end
36 end
Something went wrong with that request. Please try again.