Class: Ruby_process::Proxyobj

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_process.rb

Overview

This class handels the calling of methods on objects in the other process seamlessly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Proxyobj

Constructor. This should not be called manually but through a running ‘Ruby_process’.

Examples

proxy_obj = rp.new(:String, “Kasper”) #=> <Ruby_process::Proxyobj> proxy_obj = rp.static(:File, :open, “/tmp/somefile”) #=> <Ruby_process::Proxyobj>



377
378
379
# File 'lib/ruby_process.rb', line 377

def initialize(args)
  @args = args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Proxies all calls to the process-object.

Examples

str = rp.new(:String, “Kasper”) #=> <Ruby_process::Proxyobj::1> length_int = str.length #=> <Ruby_process::Proxyobj::2> length_int.__rp_marshal #=> 6



394
395
396
397
398
399
400
# File 'lib/ruby_process.rb', line 394

def method_missing(method, *args, &block)
  debug "Method-missing-args-before: #{args} (#{@my_pid})\n" if @debug
  real_args = @args[:rp].parse_args(args)
  debug "Method-missing-args-after: #{real_args}\n" if @debug
  
  return @args[:rp].send(:cmd => :obj_method, :id => @args[:id], :method => method, :args => real_args, &block)
end

Instance Attribute Details

#argsObject (readonly)

Hash that contains various information about the proxyobj.



371
372
373
# File 'lib/ruby_process.rb', line 371

def args
  @args
end

Instance Method Details

#__rp_marshalObject

Returns the object as the real object transfered by using the marshal-lib.

Examples

str = rp.new(:String, “Kasper”) #=> <Ruby_process::Proxyobj> str.__rp_marshal #=> “Kasper”



385
386
387
# File 'lib/ruby_process.rb', line 385

def __rp_marshal
  return Marshal.load(@args[:rp].send(:cmd => :obj_marshal, :id => @args[:id]))
end