Class: Highs::BaseArray
- Inherits:
-
Object
- Object
- Highs::BaseArray
- Defined in:
- lib/highs/array.rb
Direct Known Subclasses
Constant Summary collapse
- NOT_SET =
Object.new
Instance Method Summary collapse
-
#initialize(size, value = NOT_SET) ⇒ BaseArray
constructor
A new instance of BaseArray.
- #to_a ⇒ Object
- #to_ptr ⇒ Object
Constructor Details
#initialize(size, value = NOT_SET) ⇒ BaseArray
Returns a new instance of BaseArray.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/highs/array.rb', line 5 def initialize(size, value = NOT_SET) @size = size @ptr = if value == NOT_SET Fiddle::Pointer.malloc(size * self.class::SIZE, Fiddle::RUBY_FREE) else if value.size != size # TODO add variable name to message raise ArgumentError, "wrong size (given #{value.size}, expected #{size})" end Fiddle::Pointer[value.pack("#{self.class::FORMAT}#{size}")] end end |
Instance Method Details
#to_a ⇒ Object
19 20 21 |
# File 'lib/highs/array.rb', line 19 def to_a @ptr[0, @size * self.class::SIZE].unpack("#{self.class::FORMAT}#{@size}") end |
#to_ptr ⇒ Object
23 24 25 |
# File 'lib/highs/array.rb', line 23 def to_ptr @ptr end |