Stash is just like Hash, except that all keys are converted to Strings.
Note this doesn't yet handle default_proc.
# File lib/hashery/stash.rb, line 26 def <<(other) case other when Hash super(other.rekey{ |key| convert_key(key) }) when Array self[other[0]] = other[1] else raise ArgumentError end end
# File lib/hashery/stash.rb, line 16 def [](key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 21 def []=(key,value) super(convert_key(key), value) end
# File lib/hashery/stash.rb, line 97 def delete(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 38 def fetch(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 53 def has_key?(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 58 def include?(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 48 def key?(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 63 def member?(key) super(convert_key(key)) end
# File lib/hashery/stash.rb, line 112 def merge(other) super(other.rekey{ |key| convert_key(key) }) end
Same as update.
# File lib/hashery/stash.rb, line 107 def merge!(other) super(other.rekey{ |key| convert_key(key) }) end
# File lib/hashery/stash.rb, line 92 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/stash.rb, line 74 def rekey!(*args, &block) # for backward comptability (TODO: 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.to_s]=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/stash.rb, line 117 def replace(other) super(other.rekey{ |key| convert_key(key) }) end
# File lib/hashery/stash.rb, line 43 def store(key, value) super(convert_key(key), value) end
# File lib/hashery/stash.rb, line 127 def to_hash h = {} each{ |k,v| h[k] = v } h end
Generated with the Darkfish Rdoc Generator 2.