Class: Calcexam::Matrix
- Inherits:
-
Object
- Object
- Calcexam::Matrix
- Includes:
- Enumerable
- Defined in:
- lib/calcexam/matrix.rb
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #[](i, j = nil) ⇒ Object
- #each ⇒ Object
-
#initialize(operation = :*, x = [], y = []) ⇒ Matrix
constructor
A new instance of Matrix.
- #shuffle! ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(operation = :*, x = [], y = []) ⇒ Matrix
Returns a new instance of Matrix.
6 7 8 9 |
# File 'lib/calcexam/matrix.rb', line 6 def initialize(operation=:*, x=[], y=[]) @operation = operation @x, @y = parse_interval(x), parse_interval(y) end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
4 5 6 |
# File 'lib/calcexam/matrix.rb', line 4 def operation @operation end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/calcexam/matrix.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/calcexam/matrix.rb', line 4 def y @y end |
Instance Method Details
#[](i, j = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/calcexam/matrix.rb', line 29 def [](i, j=nil) if j.nil? j = i / @x.size i = i % @x.size end [@x[i], @y[j]] end |
#each ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/calcexam/matrix.rb', line 11 def each @x.each do |x| @y.each do |y| yield([x, y]) end end end |
#shuffle! ⇒ Object
19 20 21 22 23 |
# File 'lib/calcexam/matrix.rb', line 19 def shuffle! @x.shuffle! @y.shuffle! self end |
#size ⇒ Object
25 26 27 |
# File 'lib/calcexam/matrix.rb', line 25 def size @x.size * @y.size end |