Class: Array

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

Instance Method Summary collapse

Instance Method Details

#avgObject



107
108
109
# File 'lib/zmb/utils.rb', line 107

def avg
  sum / count
end

#list_countObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/zmb/utils.rb', line 92

def list_count
  items = {}
  
  each do |i|
    items[i] = 0 unless items.has_key?(i)
    items[i] += 1
  end
  
  items.map{ |i, c| c == 1 ? i : "#{i} (#{c})" }.join(', ')
end

#list_joinObject



88
89
90
# File 'lib/zmb/utils.rb', line 88

def list_join
  (size > 2 ? [slice(0..-2).join(', '), last] : self).join(' and ')
end

#split_seperatorsObject



80
81
82
# File 'lib/zmb/utils.rb', line 80

def split_seperators
  self
end

#sumObject



103
104
105
# File 'lib/zmb/utils.rb', line 103

def sum
  inject {|result, element| result + element}
end

#word_count(seperator = '') ⇒ Object



84
85
86
# File 'lib/zmb/utils.rb', line 84

def word_count(seperator='')
  join(seperator).size
end