Class: Array

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) avg



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

def avg
  sum / count
end

- (Object) list_count



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

- (Object) list_join



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

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

- (Object) split_seperators



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

def split_seperators
  self
end

- (Object) sum



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

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

- (Object) word_count(seperator = ''))



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

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