Class: Octave::Engine

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  load_driver(options[: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

#driverObject (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