Skip to content

Commit

Permalink
Added block usage to Matlab::Engine.new
Browse files Browse the repository at this point in the history
git-svn-id: http://matlab-ruby.rubyforge.org/svn/trunk@14 a4cadce9-4ec9-48b2-9120-f971c031a6cc
  • Loading branch information
poogle committed Feb 21, 2008
1 parent d779111 commit aa73d9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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 == 2.0.0 / 2008-01-03


* 1 bug fix * 1 bug fix
Expand Down
6 changes: 6 additions & 0 deletions README.txt
Expand Up @@ -28,6 +28,12 @@ A Ruby interface to the MATLAB interpreted language.


engine.save "/tmp/20_x_400_matrix" engine.save "/tmp/20_x_400_matrix"
engine.close 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: == REQUIREMENTS:


Expand Down
14 changes: 14 additions & 0 deletions lib/matlab/engine.rb
Expand Up @@ -13,6 +13,12 @@ module Matlab
# p engine.get_variable "z" # p engine.get_variable "z"
# #
# engine.close # 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 # Values are sent to and from MATLAB by calling a method on the
# engine with the variable name of interest. # engine with the variable name of interest.
Expand All @@ -28,6 +34,14 @@ def initialize(command = "matlab -nodesktop -nosplash", options = {})
load_driver(options[:driver]) load_driver(options[:driver])


@handle = @driver.open(command) @handle = @driver.open(command)

if block_given?
begin
yield self
ensure
close
end
end
end end


# Sends the given string to MATLAB to be evaluated # Sends the given string to MATLAB to be evaluated
Expand Down

0 comments on commit aa73d9e

Please sign in to comment.