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(rp, id, pid) ⇒ 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(rp, id, pid)
  @__rp_rp, @__rp_id, @__rp_pid = rp, id, pid
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



48
49
50
51
52
53
54
# File 'lib/ruby_process_proxyobj.rb', line 48

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

Instance Attribute Details

#__rp_idObject (readonly)

Hash that contains various information about the proxyobj.



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

def __rp_id
  @__rp_id
end

#__rp_pidObject (readonly)

Hash that contains various information about the proxyobj.



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

def __rp_pid
  @__rp_pid
end

#__rp_rpObject (readonly)

Hash that contains various information about the proxyobj.



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

def __rp_rp
  @__rp_rp
end

Instance Method Details

#__rp_destroyObject

Unsets all data on the object.



23
24
25
# File 'lib/ruby_process_proxyobj.rb', line 23

def __rp_destroy
  @__rp_id = nil, @__rp_rp = nil, @__rp_pid = nil
end

#__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(@__rp_rp.send(:cmd => :obj_marshal, :id => @__rp_id))
end