Class: Array
Instance Method Summary collapse
Instance Method Details
#average(&block) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/commonthread/monkey_patches.rb', line 93 def average(&block) sum = 0 items = 0 self.each do |n| current_value = yield(n) sum += current_value and items += 1 if current_value end if items > 0 sum.to_f / items.to_f else nil end end |
#maximum(&block) ⇒ Object
85 86 87 |
# File 'lib/commonthread/monkey_patches.rb', line 85 def maximum(&block) self.collect{|n| yield(n)}.max end |
#minimum(&block) ⇒ Object
89 90 91 |
# File 'lib/commonthread/monkey_patches.rb', line 89 def minimum(&block) self.collect{|n| yield(n)}.min end |