Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/viral_seq/hash.rb
Overview
additional methods for Class::Hash required for ViralSeq
Instance Method Summary collapse
-
#difference(other_hash) ⇒ Hash
subtract one hash (h2) from the other (h1) if the keys are identical.
-
#uniq_hash ⇒ Hash
return a new hash with the unique values of input hash as keys, and the keys of the unique values of input hash in an array as values of the new hash.
Instance Method Details
#difference(other_hash) ⇒ Hash
subtract one hash (h2) from the other (h1) if the keys are identical
14 15 16 17 18 |
# File 'lib/viral_seq/hash.rb', line 14 def difference(other_hash) reject do |k,_v| other_hash.has_key? k end end |
#uniq_hash ⇒ Hash
return a new hash with the unique values of input hash as keys, and the keys of the unique values of input hash in an array as values of the new hash
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/viral_seq/hash.rb', line 28 def uniq_hash uniq_values = self.values.uniq out_hash = {} uniq_values.each do |uniq_va| self.each do |k,v| if v == uniq_va if out_hash[uniq_va] out_hash[uniq_va] << k else out_hash[uniq_va] = [] out_hash[uniq_va] << k end end end end return out_hash end |