Class: Array
Instance Method Summary collapse
- #*(x) ⇒ Object
-
#^(other) ⇒ Object
exclusive elements.
-
#combine(other, op = nil) ⇒ Object
new array from two arrays.
-
#numbers! ⇒ Object
TODO Rewrite/Rename these:.
- #numerify! ⇒ Object
- #old_x ⇒ Object
- #to_v ⇒ Object
Instance Method Details
#*(x) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/lib/helper/lib/array.rb', line 21 def *(x) if (x.is_a? Vector rescue false) (Matrix[self] * x)[0] else old_x x end end |
#^(other) ⇒ Object
exclusive elements
6 7 8 |
# File 'lib/lib/helper/lib/array.rb', line 6 def ^(other) (self - other) | (other - self) end |
#combine(other, op = nil) ⇒ Object
new array from two arrays.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lib/helper/lib/array.rb', line 10 def combine(other, op=nil) return [] if self.empty? || other.empty? clipped = self[0..other.length-1] zipped = clipped.zip(other) if op zipped.map { |a, b| a.send(op, b) } else zipped.map { |a, b| yield(a, b) } end end |
#numbers! ⇒ Object
TODO Rewrite/Rename these:
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lib/helper/lib/array.rb', line 32 def numbers! i = length - 1 self.reverse_each do |elem| if elem.is_a? Array self[i] = elem.numbers! else elem.numeric? ? self[i] = Float(elem):self.delete_at(i) end i -= 1 end return self end |
#numerify! ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lib/helper/lib/array.rb', line 44 def numerify! self.each_index do |i| if self[i].is_a? Array self[i] = self[i].numerify! else self[i] = Float(self[i]) if self[i].numeric? end end return self end |
#old_x ⇒ Object
20 |
# File 'lib/lib/helper/lib/array.rb', line 20 alias :old_x :* |