Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/library/core_ext.rb
Instance Method Summary collapse
-
#rekey ⇒ Object
Transform keys of hash returning a new hash.
-
#rekey! ⇒ Object
In-place rekey.
Instance Method Details
#rekey ⇒ Object
Transform keys of hash returning a new hash.
18 19 20 21 22 23 24 |
# File 'lib/library/core_ext.rb', line 18 def rekey #:yield: if block_given? inject({}){|h,(k,v)| h[yield(k)]=v; h} else inject({}){|h,(k,v)| h[k.to_sym]=v; h} end end |
#rekey! ⇒ Object
In-place rekey.
29 30 31 |
# File 'lib/library/core_ext.rb', line 29 def rekey! #:yield: replace(rekey{|k| yield(k) }) end |