module Enumerable
Public Instance Methods
argfind() { |e| ... }
click to toggle source
like find, except returns the value of the block rather than the element itself.
# File lib/sup/util.rb, line 525 def argfind ret = nil find { |e| ret ||= yield(e) } ret || nil # force end
argmin() { |e| ... }
click to toggle source
# File lib/sup/util.rb, line 531 def argmin best, bestval = nil, nil each do |e| val = yield e if bestval.nil? || val < bestval best, bestval = e, val end end best end
between(startline, endline)
click to toggle source
returns all the entries which are equal to startline up to endline
# File lib/sup/util.rb, line 561 def between startline, endline select { |l| true if l == startline .. l == endline } end
map_to_hash() { |x| ... }
click to toggle source
# File lib/sup/util.rb, line 517 def map_to_hash ret = {} each { |x| ret[x] = yield(x) } ret end
map_with_index() { |x, i| ... }
click to toggle source
# File lib/sup/util.rb, line 509 def map_with_index ret = [] each_with_index { |x, i| ret << yield(x, i) } ret end
max_of() { |e| ... }
click to toggle source
# File lib/sup/util.rb, line 556 def max_of map { |e| yield e }.max end
sum()
click to toggle source
# File lib/sup/util.rb, line 515 def sum; inject(0) { |x, y| x + y }; end