RubyProcess

Start another Ruby process and manipulate it almost seamlessly.

Example

The CSV lib will not be loaded in the main process and the writing of the file will also take place in another process.

require "rubygems"
require "ruby_process"

RubyProcess.new.spawn_process do |rp|
  rp.static(:Object, :require, "csv")

  rp.static(:CSV, :open, "test.csv", "w") do |csv|
    csv << ["ID", "Name"]
    csv << [1, "Kasper"]
  end
end

Install

Add to your Gemfile and bundle.

gem "ruby_process"

Usage

With a block.

RubyProcess.new.spawn_process do |rp|
  rp.static(:File, :open, "some_file", "w") do |fp|
    fp.write("Test!")
  end
end

Almost seamless mode with ClassProxy.

RubyProcess::ClassProxy.run do |data|
  sp = data[:subproc]
  sp.static(:Object, :require, "tempfile")
  
  # Tempfile will be created in the subprocess and not in the current process.
  temp_file = RubyProcess::ClassProxy::Tempfile("temp")
end

As a variable.

rp = RubyProcess.new(debug: false)
rp.spawn_process
test_string = rp.new(:String, "Test")

Calling static methods on classes.

rp.static(:File, :open, "file_path", "w")

Spawning new objects.

file = rp.new(:File, "file_path", "r")

Serializing objects back to the main process.

rp.static(:File, :size, "file_path") #=> RubyProcess::ProxyObject
rp.static(:File, :size, "file_path").__rp_marshall #=> 2048

Contributing to RubyProcess

Copyright © 2012 Kasper Johansen. See LICENSE.txt for further details.