Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/githooker/core_ext/array/min_max.rb

Direct Known Subclasses

GitHooker::Section

Instance Method Summary collapse

Instance Method Details

#max(&block) ⇒ Object



11
12
13
14
15
16
# File 'lib/githooker/core_ext/array/min_max.rb', line 11

def max(&block)
  collection = block_given? ? collect { |obj| yield obj } : self
  collection.inject(0) { |max, num|
    max = num > max ? num : max; max
  }
end

#min(&block) ⇒ Object



4
5
6
7
8
9
# File 'lib/githooker/core_ext/array/min_max.rb', line 4

def min(&block)
  collection = block_given? ? collect { |obj| yield obj } : self
  collection.inject(Infinity) { |min, num|
    min = num < min ? num : min; min
  }
end