Class: Ruby_process::Proxyobj

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

Overview

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

Constant Summary collapse

RUBY_METHODS =

Overwrite certain convert methods.

[:to_i, :to_s, :to_str, :to_f]
PROXY_METHODS =

Overwrite certain methods.

[:send]

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>



10
11
12
# File 'lib/ruby_process_proxyobj.rb', line 10

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



43
44
45
46
47
48
49
# File 'lib/ruby_process_proxyobj.rb', line 43

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.



4
5
6
# File 'lib/ruby_process_proxyobj.rb', line 4

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”



18
19
20
# File 'lib/ruby_process_proxyobj.rb', line 18

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