Sha256: 43d7d78457ca22cc64b88c9ed2d142bfe0c7a20b75a3d82779b96f44e443d551

Contents?: true

Size: 403 Bytes

Versions: 1

Compression:

Stored size: 403 Bytes

Contents

#  options = {:key1 => 'default'}.merge(options)

class Array

	def sum (options = {})
		strict = options.fetch(:strict, true)		
		strict ? sum_strict : sum_loose
	end

	private

	def sum_strict
		total = 0
		self.each {|item| total = total + item }
		total
	end 

	def sum_loose
		total = 0
		self.each do |item| 
			val = item.is_a?(Numeric) ? item : 0
			total = total + val 
		end
		total
	end 

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
corelib-0.0.7 lib/corelib/array/math.rb