Sha256: 17e8a46fa1d436f8023b47120813f32736523c2268fdebad507d6d140f31edb6

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

class RubyProcess
  #Calls a static method on the process-side.
  #===Examples
  # rp.static(:File, :open, "/tmp/somefile", "w") do |fp|
  #   fp.write("Test")
  # end
  def static(classname, method, *args, &block)
    debug "Args-before: #{args} (#{@my_pid})\n" if @debug
    real_args = parse_args(args)
    debug "Real-args: #{real_args}\n" if @debug

    return send(cmd: :static, classname: classname, method: method, args: real_args, &block)
  end

  #Process-method for the 'static'-method.
  def cmd_static(obj)
    if obj.key?(:block)
      real_block = proc{|*args|
        debug "Block called! #{args}\n" if @debug
        send(cmd: :block_call, block_id: obj[:block][:id], answer_id: obj[:send_id], args: handle_return_args(args))
      }

      block = block_with_arity(arity: obj[:block][:arity], &real_block)
    else
      block = nil
    end

    debug "Static-args-before: #{obj[:args]}\n" if @debug
    real_args = read_args(obj[:args])
    debug "Static-args-after: #{real_args}\n" if @debug

    const = obj[:classname].to_s.split("::").inject(Object, :const_get)
    retobj = const.__send__(obj[:method], *real_args, &block)
    return handle_return_object(retobj)
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ruby_process-0.0.13 cmds/static.rb
RubyProcess-0.0.12 cmds/static.rb