CastingHash is just like Hash, except that all keys and values are passed through casting procedures.
# File lib/more/facets/casting_hash.rb, line 59 59: def <<(other) 60: case other 61: when Hash 62: super(cast(other)) 63: when Array 64: self[other[0]] = other[1] 65: else 66: raise ArgumentError 67: end 68: end
# File lib/more/facets/casting_hash.rb, line 49 49: def [](k) 50: super(key_proc[k]) 51: end
# File lib/more/facets/casting_hash.rb, line 54 54: def []=(k,v) 55: super(key_proc[k], value_proc[v]) 56: end
# File lib/more/facets/casting_hash.rb, line 118 118: def delete(k) 119: super(key_proc[k]) 120: end
# File lib/more/facets/casting_hash.rb, line 70 70: def fetch(k) 71: super(key_proc[k]) 72: end
# File lib/more/facets/casting_hash.rb, line 85 85: def has_key?(k) 86: super(key_proc[k]) 87: end
# File lib/more/facets/casting_hash.rb, line 80 80: def key?(k) 81: super(key_proc[k]) 82: end
# File lib/more/facets/casting_hash.rb, line 29 29: def key_proc 30: @key_proc 31: end
# File lib/more/facets/casting_hash.rb, line 34 34: def key_proc=(proc) 35: @key_proc = proc.to_proc 36: end
Same as #.
# File lib/more/facets/casting_hash.rb, line 128 128: def merge!(other) 129: super(cast(other)) 130: end
# File lib/more/facets/casting_hash.rb, line 113 113: def rekey(*args, &block) 114: dup.rekey!(*args, &block) 115: 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/casting_hash.rb, line 95 95: def rekey!(*args, &block) 96: # for backward comptability (DEPRECATE?). 97: block = args.pop.to_sym.to_proc if args.size == 1 98: if args.empty? 99: block = lambda{|k| k} unless block 100: keys.each do |k| 101: nk = block[k] 102: self[nk] = delete(k) #if nk 103: end 104: else 105: raise ArgumentError, "3 for 2" if block 106: to, from = *args 107: self[to] = delete(from) if has_key?(from) 108: end 109: self 110: end
# File lib/more/facets/casting_hash.rb, line 133 133: def replace(other) 134: super(cast(other)) 135: end
# File lib/more/facets/casting_hash.rb, line 75 75: def store(k, v) 76: super(key_proc[k], value_proc[v]) 77: end
# File lib/more/facets/casting_hash.rb, line 143 143: def to_hash 144: h = {}; each{ |k,v| h[k] = v }; h 145: end
# File lib/more/facets/casting_hash.rb, line 123 123: def update(other) 124: super(cast(other)) 125: end
# File lib/more/facets/casting_hash.rb, line 39 39: def value_proc 40: @value_proc 41: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.