Module: Rserve::With2DSizes
- Defined in:
- lib/rserve/with2dsizes.rb
Instance Attribute Summary collapse
-
#column_size ⇒ Object
readonly
Returns the value of attribute column_size.
-
#row_size ⇒ Object
readonly
Returns the value of attribute row_size.
Instance Method Summary collapse
Instance Attribute Details
#column_size ⇒ Object (readonly)
Returns the value of attribute column_size.
5 6 7 |
# File 'lib/rserve/with2dsizes.rb', line 5 def column_size @column_size end |
#row_size ⇒ Object (readonly)
Returns the value of attribute row_size.
5 6 7 |
# File 'lib/rserve/with2dsizes.rb', line 5 def row_size @row_size end |
Instance Method Details
#at_2d(i, j) ⇒ Object
15 16 17 |
# File 'lib/rserve/with2dsizes.rb', line 15 def at_2d(i,j) self[i + j * row_size] end |
#column(j) ⇒ Object
24 25 26 27 |
# File 'lib/rserve/with2dsizes.rb', line 24 def column(j) return nil unless (-column_size...column_size) === j self[(j * row_size), row_size] end |
#row(i) ⇒ Object
19 20 21 22 |
# File 'lib/rserve/with2dsizes.rb', line 19 def row(i) return nil unless (-row_size...row_size) === i each_slice(row_size).map {|col| col[i]} end |
#sizes=(sizes) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/rserve/with2dsizes.rb', line 7 def sizes=(sizes) raise ArgumentError, "sizes must be of size 2" unless (sizes.size == 2) raise ArgumentError, "mismatch between provided size info and actual number of elements" unless self.size == (sizes[0] * sizes[1]) @row_size = sizes[0] @column_size = sizes[1] end |