Stash is just like Hash, except that all keys are converted to Strings.
Note this doesn’t yet handle default_proc.
# File lib/more/facets/stash.rb, line 26
26: def <<(other)
27: case other
28: when Hash
29: super(other.rekey{ |key| convert_key(key) })
30: when Array
31: self[other[0]] = other[1]
32: else
33: raise ArgumentError
34: end
35: end
# File lib/more/facets/stash.rb, line 16
16: def [](key)
17: super(convert_key(key))
18: end
# File lib/more/facets/stash.rb, line 21
21: def []=(key,value)
22: super(convert_key(key), value)
23: end
# File lib/more/facets/stash.rb, line 97
97: def delete(key)
98: super(convert_key(key))
99: end
# File lib/more/facets/stash.rb, line 38
38: def fetch(key)
39: super(convert_key(key))
40: end
# File lib/more/facets/stash.rb, line 53
53: def has_key?(key)
54: super(convert_key(key))
55: end
# File lib/more/facets/stash.rb, line 58
58: def include?(key)
59: super(convert_key(key))
60: end
# File lib/more/facets/stash.rb, line 48
48: def key?(key)
49: super(convert_key(key))
50: end
# File lib/more/facets/stash.rb, line 63
63: def member?(key)
64: super(convert_key(key))
65: end
# File lib/more/facets/stash.rb, line 112
112: def merge(other)
113: super(other.rekey{ |key| convert_key(key) })
114: end
Same as #.
# File lib/more/facets/stash.rb, line 107
107: def merge!(other)
108: super(other.rekey{ |key| convert_key(key) })
109: end
# File lib/more/facets/stash.rb, line 92
92: def rekey(*args, &block)
93: dup.rekey!(*args, &block)
94: end
Synonym for Hash#rekey, but modifies the receiver in place (and returns it).
foo = { :name=>'Gavin', :wife=>:Lisa }.to_stash
foo.rekey!{ |k| k.upcase } #=> { "NAME"=>"Gavin", "WIFE"=>:Lisa }
foo.inspect #=> { "NAME"=>"Gavin", "WIFE"=>:Lisa }
# File lib/more/facets/stash.rb, line 74
74: def rekey!(*args, &block)
75: # for backward comptability (TODO: DEPRECATE?).
76: block = args.pop.to_sym.to_proc if args.size == 1
77: if args.empty?
78: block = lambda{|k| k} unless block
79: keys.each do |k|
80: nk = block[k]
81: self[nk.to_s]=delete(k) #if nk
82: end
83: else
84: raise ArgumentError, "3 for 2" if block
85: to, from = *args
86: self[to] = delete(from) if has_key?(from)
87: end
88: self
89: end
# File lib/more/facets/stash.rb, line 117
117: def replace(other)
118: super(other.rekey{ |key| convert_key(key) })
119: end
# File lib/more/facets/stash.rb, line 43
43: def store(key, value)
44: super(convert_key(key), value)
45: end
# File lib/more/facets/stash.rb, line 127
127: def to_hash
128: h = {}
129: each{ |k,v| h[k] = v }
130: h
131: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.