Class: Carbuncle::Matrix::Line
- Includes:
- Vectorizable
- Defined in:
- gems/carbuncle-math/mrblib/matrix.rb
Overview
A line is a row or column of a matrix.
Constant Summary
Constants included from Vectorizable
Constants included from Enumerable
Instance Attribute Summary collapse
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
-
#initialize(matrix, index, vertical) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
Methods included from Vectorizable
#%, #*, #**, #+, #-, #-@, #/, #<<, #>>, #each, #length, #to_s
Methods included from Enumerable
__update_hash, #all?, #any?, #chain, #collect, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_slice, #each_with_index, #each_with_object, #entries, #filter_map, #find_all, #find_index, #first, #flat_map, #grep, #group_by, #hash, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #sort, #sort_by, #sum, #take, #take_while, #tally, #to_h, #uniq, #zip
Constructor Details
#initialize(matrix, index, vertical) ⇒ Line
Returns a new instance of Line.
14 15 16 17 18 19 20 21 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 14 def initialize(matrix, index, vertical) @matrix = matrix @index = index @indexes = Array.new(4) do |v| vertical ? [index, v] : [v, index] end end |
Instance Attribute Details
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
12 13 14 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 12 def matrix @matrix end |
Instance Method Details
#[](index) ⇒ Object
23 24 25 26 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 23 def [](index) i, j = @indexes[index] matrix[i, j] end |
#[]=(index, value) ⇒ Object
28 29 30 31 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 28 def []=(index, value) i, j = @indexes[index] matrix[i, j] = value end |
#inspect ⇒ Object
40 41 42 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 40 def inspect "#{self.class.name}[#{@index}](#{to_a.join(', ')})" end |
#size ⇒ Object
44 45 46 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 44 def size 4 end |
#to_a ⇒ Object
33 34 35 36 37 38 |
# File 'gems/carbuncle-math/mrblib/matrix.rb', line 33 def to_a @indexes.map do |indexes| i, j = indexes matrix[i, j] end end |