CastingHash is just like Hash, except that all keys and values are passed through casting procedures.
# File lib/hashery/castinghash.rb, line 59 def <<(other) case other when Hash super(cast(other)) when Array self[other[0]] = other[1] else raise ArgumentError end end
# File lib/hashery/castinghash.rb, line 49 def [](k) super(key_proc[k]) end
# File lib/hashery/castinghash.rb, line 54 def []=(k,v) super(key_proc[k], value_proc[v]) end
# File lib/hashery/castinghash.rb, line 118 def delete(k) super(key_proc[k]) end
# File lib/hashery/castinghash.rb, line 70 def fetch(k) super(key_proc[k]) end
# File lib/hashery/castinghash.rb, line 85 def has_key?(k) super(key_proc[k]) end
# File lib/hashery/castinghash.rb, line 80 def key?(k) super(key_proc[k]) end
# File lib/hashery/castinghash.rb, line 29 def key_proc @key_proc end
# File lib/hashery/castinghash.rb, line 34 def key_proc=(proc) @key_proc = proc.to_proc end
Same as update.
# File lib/hashery/castinghash.rb, line 128 def merge!(other) super(cast(other)) end
# File lib/hashery/castinghash.rb, line 113 def rekey(*args, &block) dup.rekey!(*args, &block) 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/hashery/castinghash.rb, line 95 def rekey!(*args, &block) # for backward comptability (DEPRECATE?). block = args.pop.to_sym.to_proc if args.size == 1 if args.empty? block = lambda{|k| k} unless block keys.each do |k| nk = block[k] self[nk] = delete(k) #if nk end else raise ArgumentError, "3 for 2" if block to, from = *args self[to] = delete(from) if has_key?(from) end self end
# File lib/hashery/castinghash.rb, line 133 def replace(other) super(cast(other)) end
# File lib/hashery/castinghash.rb, line 75 def store(k, v) super(key_proc[k], value_proc[v]) end
# File lib/hashery/castinghash.rb, line 143 def to_hash h = {}; each{ |k,v| h[k] = v }; h end
# File lib/hashery/castinghash.rb, line 123 def update(other) super(cast(other)) end
# File lib/hashery/castinghash.rb, line 39 def value_proc @value_proc end
Generated with the Darkfish Rdoc Generator 2.