Object
Core Extensions
Non-inplace rekey! method.
# File lib/hashery/stash.rb, line 176 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 } foo.rekey!{ |k| k.to_s } #=> { "name"=>"Gavin", "wife"=>:Lisa } foo.inspect #=> { "name"=>"Gavin", "wife"=>:Lisa }
This method comes from Ruby Facets.
# File lib/hashery/stash.rb, line 158 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.to_sym} 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] = self.delete(from) if self.has_key?(from) end self end
Convert a Hash into a BasicStruct.
# File lib/hashery/basicstruct.rb, line 246 def to_basicstruct BasicStruct[self] end
Generated with the Darkfish Rdoc Generator 2.