Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ctioga2/utils.rb
Overview
Here, we define an additional function in the Hash class: without
Instance Method Summary collapse
-
#rename_key(old, new) ⇒ Object
Renames the given key.
-
#strip_if_false!(keys) ⇒ Object
Strip the given keys if they evaluate to false.
-
#without(*args) ⇒ Object
Returns a copy of the hash without the given keys.
Instance Method Details
#rename_key(old, new) ⇒ Object
Renames the given key
728 729 730 731 |
# File 'lib/ctioga2/utils.rb', line 728 def rename_key(old, new) self[new] = self[old] self.delete(old) end |
#strip_if_false!(keys) ⇒ Object
Strip the given keys if they evaluate to false
734 735 736 737 738 739 740 |
# File 'lib/ctioga2/utils.rb', line 734 def strip_if_false!(keys) for k in keys if key?(k) and (not self[k]) self.delete(k) end end end |
#without(*args) ⇒ Object
Returns a copy of the hash without the given keys
719 720 721 722 723 724 725 |
# File 'lib/ctioga2/utils.rb', line 719 def without(*args) ret = self.dup for a in args.flatten ret.delete(a) end return ret end |