Module: Averager::ObjectExtensions

Defined in:
lib/averager.rb

Instance Method Summary collapse

Instance Method Details

#each_with_avg(options = {}) ⇒ Object

Raises:

  • (NoMethodError)


10
11
12
13
14
15
16
17
18
19
# File 'lib/averager.rb', line 10

def each_with_avg(options = {})
  raise NoMethodError if !self.respond_to?(:each)
  options[:expected] ||= self.count if self.respond_to?(:count)
  Averager.new(options) do |a|
    self.each do |element|
      yield(element)
      a.avg
    end
  end
end