Feature #10444 » implement_matrix.rb.patch
lib/matrix.rb  

1685  1685 
# * Vector.basis(size: n, index: k) 
1686  1686 
# 
1687  1687 
# To access elements: 
1688 
# * #[](i)


1688 
# * #[](arg)


1689  1689 
# 
1690  1690 
# To enumerate the elements: 
1691  1691 
# * #each2(v) 
...  ...  
1770  1770 
# ACCESSING 
1771  1771 
# 
1772 
# Returns element number +i+ (starting at zero) of the vector. 

1772 
# :callseq: 

1773 
# vector[index] > obj or nil 

1774 
# vector[range] > new_vector or nil 

1775 
# 

1776 
# Element Assignment — the element at index or 

1777 
# replaces a new vector specified by the range of indices. 

1778 
# 

1779 
# Vector[1, 2, 3][1] 

1780 
# => 2 

1781 
# 

1782 
# Vector[1, 2, 3][1..1] 

1783 
# => Vector[2, 3] 

1784 
# 

1785 
# Like Array#[], Negative indices will count backward from the end of the vector. 

1773  1786 
# 
1774 
def [](i) 

1775 
@elements[i] 

1787 
def [](arg) 

1788 
return unless elements = @elements[arg] 

1789 
arg.is_a?(Range) ? Vector[*elements] : elements 

1776  1790 
end 
1777  1791 
alias element [] 
1778  1792 
alias component [] 
1779 
 