diff --git a/History.txt b/History.txt index e2d03e6..2396c84 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +== 2.0.1 / 2008-02-21 + +* 1 minor enhancement + * Added block usage to Matlab::Engine.new + == 2.0.0 / 2008-01-03 * 1 bug fix diff --git a/README.txt b/README.txt index fe653f1..6f75aab 100644 --- a/README.txt +++ b/README.txt @@ -28,6 +28,12 @@ A Ruby interface to the MATLAB interpreted language. engine.save "/tmp/20_x_400_matrix" engine.close + + # May also use block syntax for new + Matlab::Engine.new do |engine| + engine.put_variable "x", 123.456 + engine.get_variable "x" + end == REQUIREMENTS: diff --git a/lib/matlab/engine.rb b/lib/matlab/engine.rb index 1addc58..83ac62b 100644 --- a/lib/matlab/engine.rb +++ b/lib/matlab/engine.rb @@ -13,6 +13,12 @@ module Matlab # p engine.get_variable "z" # # engine.close + # + # # May also use block syntax for new + # Matlab::Engine.new do |engine| + # engine.put_variable "x", 123.456 + # engine.get_variable "x" + # end # # Values are sent to and from MATLAB by calling a method on the # engine with the variable name of interest. @@ -28,6 +34,14 @@ def initialize(command = "matlab -nodesktop -nosplash", options = {}) load_driver(options[:driver]) @handle = @driver.open(command) + + if block_given? + begin + yield self + ensure + close + end + end end # Sends the given string to MATLAB to be evaluated