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



591
592
593
594
# File 'lib/ctioga2/utils.rb', line 591

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



597
598
599
600
601
602
603
# File 'lib/ctioga2/utils.rb', line 597

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



582
583
584
585
586
587
588
# File 'lib/ctioga2/utils.rb', line 582

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