Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/ptj/ext/datamapper_collection.rb
Instance Method Summary collapse
Instance Method Details
#analyze ⇒ Object
45 46 47 48 49 |
# File 'lib/ptj/ext/datamapper_collection.rb', line 45 def analyze h = Hash.new(0) self.each { | v | h.store(v, h[v]+1) } h end |
#analyze_and_sort ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ptj/ext/datamapper_collection.rb', line 51 def analyze_and_sort b = Hash.new(0) self.each { | v | b.store(v, b[v]+1) } b = b.sort_by { |k,v| -1*v } b end |
#analyze_and_sort_key ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ptj/ext/datamapper_collection.rb', line 58 def analyze_and_sort_key b = Hash.new(0) self.each { | v | b.store(v, b[v]+1) } b = b.sort_by { |k,v| k } b end |