Class: Array
- Defined in:
- lib/algebra/array-supplement.rb,
lib/algebra/import-module.rb
Overview
Array Supplements
by Shin-ichiro Hara
Version 1.2 (2001.07.23)
Instance Method Summary collapse
- #each_pair ⇒ Object
- #each_pair_with_index ⇒ Object
- #inner_product(other) ⇒ Object
- #rsort ⇒ Object
- #rsort! ⇒ Object
- #sumation ⇒ Object
Instance Method Details
#each_pair ⇒ Object
8 9 10 11 12 13 14 15 |
# 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 ⇒ Object
17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
38 39 40 41 42 43 44 |
# 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 ⇒ Object
32 33 34 35 36 |
# File 'lib/algebra/array-supplement.rb', line 32 def rsort s = sort s.reverse! s end |
#rsort! ⇒ Object
26 27 28 29 30 |
# File 'lib/algebra/array-supplement.rb', line 26 def rsort! sort! reverse! self end |
#sumation ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/algebra/array-supplement.rb', line 46 def sumation sum = 0 each do |x| sum += x end sum end |