Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/helpers/hash_helpers.rb
Overview
from Facets via Hashery
Instance Method Summary collapse
Instance Method Details
#rekey(*args, &block) ⇒ Object
25 26 27 |
# File 'lib/helpers/hash_helpers.rb', line 25 def rekey(*args, &block) dup.rekey!(*args, &block) end |
#rekey!(*args, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/helpers/hash_helpers.rb', line 8 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 |