Class: Matrix
- Inherits:
-
Object
- Object
- Matrix
- Defined in:
- lib/generic/matrix.rb
Instance Method Summary collapse
- #get(at) ⇒ Object
-
#initialize ⇒ Matrix
constructor
A new instance of Matrix.
- #m_size ⇒ Object
- #n_size ⇒ Object
- #set(at, value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Matrix
Returns a new instance of Matrix.
2 3 4 5 |
# File 'lib/generic/matrix.rb', line 2 def initialize() @mat = [] @n = 0 end |
Instance Method Details
#get(at) ⇒ Object
22 23 24 25 26 |
# File 'lib/generic/matrix.rb', line 22 def get(at) i = at[0] j = at[1] @mat[i][j] end |
#m_size ⇒ Object
11 12 13 |
# File 'lib/generic/matrix.rb', line 11 def m_size @mat.size end |
#n_size ⇒ Object
7 8 9 |
# File 'lib/generic/matrix.rb', line 7 def n_size @n end |
#set(at, value) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/generic/matrix.rb', line 15 def set(at, value) (at) i = at[0] j = at[1] @mat[i][j] = value end |
#to_s ⇒ Object
28 29 30 31 32 33 |
# File 'lib/generic/matrix.rb', line 28 def to_s p @mat # print "[" # print @mat.join(",\n") # print "]\n" end |