Sha256: 9077b02e7b2756bd9695cbea82afd0ba0cad3cc80bb6d2162d3e8e41f8a7e512

Contents?: true

Size: 429 Bytes

Versions: 6

Compression:

Stored size: 429 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

6 entries across 6 versions & 1 rubygems

Version Path
corelib-0.0.6 lib/corelib/array/math.rb
corelib-0.0.5 lib/corelib/array/math.rb
corelib-0.0.4 lib/corelib/array/math.rb
corelib-0.0.3 lib/corelib/array/math.rb
corelib-0.0.2 lib/corelib/array/math.rb
corelib-0.0.1 lib/corelib/array/math.rb