class Array
Array
Supplements
by Shin-ichiro Hara
Version 1.2 (2001.07.23)
Public Instance Methods
each_pair() { |x, y| ... }
click to toggle source
# File lib/algebra/array-supplement.rb, line 8 def each_pair each_with_index do |x, i| (i + 1).upto(size - 1) do |j| y = self[j] yield(x, y) end end end
each_pair_with_index() { |x, y, i, j| ... }
click to toggle source
# File lib/algebra/array-supplement.rb, line 17 def each_pair_with_index each_with_index do |x, i| (i + 1).upto(size - 1) do |j| y = self[j] yield(x, y, i, j) end end end
inner_product(other)
click to toggle source
# File lib/algebra/array-supplement.rb, line 38 def inner_product(other) sum = 0 each_with_index do |x, i| sum += x * other[i] end sum end
rsort()
click to toggle source
# File lib/algebra/array-supplement.rb, line 32 def rsort s = sort s.reverse! s end
rsort!()
click to toggle source
# File lib/algebra/array-supplement.rb, line 26 def rsort! sort! reverse! self end
sumation()
click to toggle source
# File lib/algebra/array-supplement.rb, line 46 def sumation sum = 0 each do |x| sum += x end sum end