Feature #10444 » implement_matrix.rb.patch
| lib/matrix.rb | ||
|---|---|---|
| # * Vector.basis(size: n, index: k) | ||
| # | ||
| # To access elements: | ||
| # * #[](i) | ||
| # * #[](arg) | ||
| # | ||
| # To enumerate the elements: | ||
| # * #each2(v) | ||
| ... | ... | |
|   # ACCESSING | ||
|   # | ||
|   # Returns element number +i+ (starting at zero) of the vector. | ||
|   # :call-seq: | ||
|   #   vector[index] -> obj        or nil | ||
|   #   vector[range] -> new_vector or nil | ||
|   # | ||
|   # Element Assignment — the element at index or | ||
|   # replaces a new vector specified by the range of indices. | ||
|   # | ||
|   #   Vector[1, 2, 3][1] | ||
|   #     => 2 | ||
|   # | ||
|   #   Vector[1, 2, 3][1..-1] | ||
|   #     => Vector[2, 3] | ||
|   # | ||
|   # Like Array#[], Negative indices will count backward from the end of the vector. | ||
|   # | ||
|   def [](i) | ||
|     @elements[i] | ||
|   def [](arg) | ||
|     return unless elements = @elements[arg] | ||
|     arg.is_a?(Range) ? Vector[*elements] : elements | ||
|   end | ||
|   alias element [] | ||
|   alias component [] | ||