Parent

Stash

Stash is just like Hash, except that all keys are converted to Strings.

Note this doesn’t yet handle default_proc.

Public Class Methods

[](*hash) click to toggle source
    # File lib/more/facets/stash.rb, line 9
 9:   def self.[](*hash)
10:     s = new
11:     super(*hash).each{ |k,v| s[k] = v }
12:     s
13:   end

Public Instance Methods

<<(other) click to toggle source
    # 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
[](key) click to toggle source
    # File lib/more/facets/stash.rb, line 16
16:   def [](key)
17:     super(convert_key(key))
18:   end
[]=(key,value) click to toggle source
    # File lib/more/facets/stash.rb, line 21
21:   def []=(key,value)
22:     super(convert_key(key), value)
23:   end
delete(key) click to toggle source
    # File lib/more/facets/stash.rb, line 97
97:   def delete(key)
98:     super(convert_key(key))
99:   end
fetch(key) click to toggle source
    # File lib/more/facets/stash.rb, line 38
38:   def fetch(key)
39:     super(convert_key(key))
40:   end
has_key?(key) click to toggle source
    # File lib/more/facets/stash.rb, line 53
53:   def has_key?(key)
54:     super(convert_key(key))
55:   end
include?(key) click to toggle source
    # File lib/more/facets/stash.rb, line 58
58:   def include?(key)
59:     super(convert_key(key))
60:   end
key?(key) click to toggle source
    # File lib/more/facets/stash.rb, line 48
48:   def key?(key)
49:     super(convert_key(key))
50:   end
member?(key) click to toggle source
    # File lib/more/facets/stash.rb, line 63
63:   def member?(key)
64:     super(convert_key(key))
65:   end
merge(other) click to toggle source
     # File lib/more/facets/stash.rb, line 112
112:   def merge(other)
113:     super(other.rekey{ |key| convert_key(key) })
114:   end
merge!(other) click to toggle source

Same as #.

     # File lib/more/facets/stash.rb, line 107
107:   def merge!(other)
108:     super(other.rekey{ |key| convert_key(key) })
109:   end
rekey(*args, &block) click to toggle source
    # File lib/more/facets/stash.rb, line 92
92:   def rekey(*args, &block)
93:     dup.rekey!(*args, &block)
94:   end
rekey!(*args, &block) click to toggle source

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
replace(other) click to toggle source
     # File lib/more/facets/stash.rb, line 117
117:   def replace(other)
118:     super(other.rekey{ |key| convert_key(key) })
119:   end
store(key, value) click to toggle source
    # File lib/more/facets/stash.rb, line 43
43:   def store(key, value)
44:     super(convert_key(key), value)
45:   end
to_h() click to toggle source
Alias for: to_hash
to_hash() click to toggle source
     # 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
Also aliased as: to_h
update(other) click to toggle source
     # File lib/more/facets/stash.rb, line 102
102:   def update(other)
103:     super(other.rekey{ |key| convert_key(key) })
104:   end
values_at(*keys) click to toggle source
     # File lib/more/facets/stash.rb, line 122
122:   def values_at(*keys)
123:     super(*keys.map{ |key| convert_key(key) })
124:   end

Private Instance Methods

convert_key(key) click to toggle source
     # File lib/more/facets/stash.rb, line 137
137:     def convert_key(key)
138:       key.to_s
139:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.