Class: Octave::Engine
- Inherits:
-
Object
- Object
- Octave::Engine
- Defined in:
- lib/octave/engine.rb
Overview
The Engine class encapsulates a single connection to a Octave instance. Usage:
require 'octave'
engine = Octave::Engine.new
engine.eval "123.456 * 789.101112"
engine.rand(10)
Functions are called in Octave by calling a method on the engine with the function name of interest and passing any parameters as needed.
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
A reference to the underlying Octave driver used by this engine.
Instance Method Summary collapse
-
#get_variable(name) ⇒ Object
Retrieve a variable from Octave with the given name.
-
#initialize(options = {}) ⇒ Engine
constructor
Create a new Engine object that connects to Octave.
-
#method_missing(method_id, *args) ⇒ Object
Call the Octave function via a given name.
-
#put_variable(name, value) ⇒ Object
Put a variable in to Octave with the given name.
Constructor Details
#initialize(options = {}) ⇒ Engine
Create a new Engine object that connects to Octave
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/octave/engine.rb', line 19 def initialize( = {}) load_driver([:driver]) if block_given? begin yield self ensure close end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
Call the Octave function via a given name
42 43 44 45 46 |
# File 'lib/octave/engine.rb', line 42 def method_missing(method_id, *args) method_name = method_id.id2name @driver.feval(method_name, *args) end |
Instance Attribute Details
#driver ⇒ Object (readonly)
A reference to the underlying Octave driver used by this engine.
16 17 18 |
# File 'lib/octave/engine.rb', line 16 def driver @driver end |
Instance Method Details
#get_variable(name) ⇒ Object
Retrieve a variable from Octave with the given name
37 38 39 |
# File 'lib/octave/engine.rb', line 37 def get_variable(name) @driver.get_variable(name) end |
#put_variable(name, value) ⇒ Object
Put a variable in to Octave with the given name
32 33 34 |
# File 'lib/octave/engine.rb', line 32 def put_variable(name, value) @driver.put_variable(name, value) end |