Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/utils.rb

Overview

Here, we define an additional function in the Hash class: without

Instance Method Summary collapse

Instance Method Details

#rename_key(old, new) ⇒ Object

Renames the given key



683
684
685
686
# File 'lib/ctioga2/utils.rb', line 683

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



689
690
691
692
693
694
695
# File 'lib/ctioga2/utils.rb', line 689

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



674
675
676
677
678
679
680
# File 'lib/ctioga2/utils.rb', line 674

def without(*args)
  ret = self.dup
  for a in args.flatten
    ret.delete(a)
  end
  return ret
end