非常教程

Ruby 2.4参考手册

DRb

DRb::DRbObject

Parent:Object

对象包装对远程drb对象的引用。

此对象上的方法调用将被中继到此对象是存根的远程对象。

公共类方法

_load(s) Show source

解组编组的DRbObject。

如果被引用的对象位于本地服务器中,则返回该对象本身。否则,将创建一个新的DRbObject以充当远程引用对象的存根。

# File lib/drb/drb.rb, line 1052
def self._load(s)
  uri, ref = Marshal.load(s)

  if DRb.here?(uri)
    obj = DRb.to_obj(ref)
    if ((! obj.tainted?) && Thread.current[:drb_untaint])
      Thread.current[:drb_untaint].push(obj)
    end
    return obj
  end

  self.new_with(uri, ref)
end

new(obj, uri=nil) Show source

创建一个新的远程对象存根。

obj是我们要创建存根的(本地)对象。通常情况是这样niluri是将成为存根的远程对象的URI。

# File lib/drb/drb.rb, line 1093
def initialize(obj, uri=nil)
  @uri = nil
  @ref = nil
  if obj.nil?
    return if uri.nil?
    @uri, option = DRbProtocol.uri_option(uri, DRb.config)
    @ref = DRbURIOption.new(option) unless option.nil?
  else
    @uri = uri ? uri : (DRb.uri rescue nil)
    @ref = obj ? DRb.to_id(obj) : nil
  end
end

new_with(uri, ref) Show source

给定远程主机uri和对象的参考信息,创建一个DRb :: DRbObject ref

# File lib/drb/drb.rb, line 1069
def self.new_with(uri, ref)
  it = self.allocate
  it.instance_variable_set(:@uri, uri)
  it.instance_variable_set(:@ref, ref)
  it
end

new_with_uri(uri) Show source

仅从一个URI创建一个新的DRbObject。

# File lib/drb/drb.rb, line 1077
def self.new_with_uri(uri)
  self.new(nil, uri)
end

公共实例方法

__drbref() Show source

获取对象的引用,如果是本地的。

# File lib/drb/drb.rb, line 1112
def __drbref
  @ref
end

__drburi() Show source

获取远程对象的URI。

# File lib/drb/drb.rb, line 1107
def __drburi
  @uri
end

_dump(lv) Show source

Marshall表示这个项目.

对象的URI和ref被编组。

# File lib/drb/drb.rb, line 1084
def _dump(lv)
  Marshal.dump([@uri, @ref])
end

method_missing(msg_id, *a, &b) Show source

将方法调用路由到引用的远程对象。

# File lib/drb/drb.rb, line 1132
def method_missing(msg_id, *a, &b)
  if DRb.here?(@uri)
    obj = DRb.to_obj(@ref)
    DRb.current_server.check_insecure_method(obj, msg_id)
    return obj.__send__(msg_id, *a, &b)
  end

  succ, result = self.class.with_friend(@uri) do
    DRbConn.open(@uri) do |conn|
      conn.send_message(self, msg_id, a, b)
    end
  end

  if succ
    return result
  elsif DRbUnknown === result
    raise result
  else
    bt = self.class.prepare_backtrace(@uri, result)
    result.set_backtrace(bt + caller)
    raise result
  end
end

respond_to?(msg_id,priv = false)显示源

路线respond_to?到被引用的远程对象。

# File lib/drb/drb.rb, line 1120
def respond_to?(msg_id, priv=false)
  case msg_id
  when :_dump
    true
  when :marshal_dump
    false
  else
    method_missing(:respond_to?, msg_id, priv)
  end
end
Ruby 2.4

Ruby 是一种面向对象、命令式、函数式、动态的通用编程语言,是世界上最优美而巧妙的语言。

主页 https://www.ruby-lang.org/
源码 https://github.com/ruby/ruby
版本 2.4
发布版本 2.4.1

Ruby 2.4目录

1.缩略 | Abbrev
2.ARGF
3.数组 | Array
4.Base64
5.基本对象 | BasicObject
6.基准测试 | Benchmark
7.BigDecimal
8.绑定 | Binding
9.CGI
10.类 | Class
11.比较 | Comparable
12.负责 | Complex
13.计算续体 | Continuation
14.覆盖 | Coverage
15.CSV
16.日期 | Date
17.日期时间 | DateTime
18.DBM
19.代理 | Delegator
20.摘要 | Digest
21.Dir
22.DRb
23.编码 | Encoding
24.枚举 | Enumerable
25.枚举 | Enumerator
26.ENV
27.ERB
28.错误 | Errors
29.Etc
30.期望值 | Exception
31.错误类 | FalseClass
32.Fiber
33.Fiddle
34.文件 | File
35.文件实用程序 | FileUtils
36.查找 | Find
37.浮点 | Float
38.Forwardable
39.GC
40.GDBM
41.GetoptLong
42.Hash
43.Integer
44.IO
45.IPAddr
46.JSON
47.Kernel
48.语言 | 3Language
49.记录 | Logger
50.编排 | Marshal
51.MatchData
52.数学 | Math
53.矩阵 | Matrix
54.方法 | Method
55.模型 | Module
56.监控 | Monitor
57. 互斥 | Mutex
58.Net
59.Net::FTP
60.Net::HTTP
61.Net::IMAP
62.Net::SMTP
63.NilClass
64.数字 | Numeric
65.对象 | Object
66.ObjectSpace
67.Observable
68.Open3
69.OpenSSL
70.OpenStruct
71.OpenURI
72.OptionParser
73.路径名 | Pathname
74.完整输出 | PrettyPrint
75.Prime
76.Proc
77.过程 | Process
78.PStore
79.PTY
80.队列 | Queue
81.随机 | Random
82.范围 | Range
83.合理的 | Rational
84.Readline
85.Regexp
86.Resolv
87.Ripper
88.RubyVM
89.Scanf
90.SDBM
91.SecureRandom
92.Set
93.Shell
94.信号 | Signal
95.Singleton
96.套接字 | Socket
97.字符串 | String
98.StringIO
99.StringScanner
100.结构 | Struct