Class: Erlang::Pid
- Inherits:
-
Object
- Object
- Erlang::Pid
- Defined in:
- lib/erlang/pid.rb
Overview
A Pid
is a process identifier object obtained from erlang:spawn/3
.
Creating Pids
Erlang::Pid["nonode@nohost", 38, 0, 0]
# => Erlang::Pid[:"nonode@nohost", 38, 0, 0]
Instance Attribute Summary collapse
-
#creation ⇒ Integer
readonly
Return the creation for this
Pid
. -
#id ⇒ Integer
readonly
Return the id for this
Pid
. -
#node ⇒ Atom
readonly
Return the node for this
Pid
. -
#serial ⇒ Integer
readonly
Return the serial for this
Pid
.
Class Method Summary collapse
-
.[](node, id, serial = 0, creation = 0) ⇒ Pid
Create a new
Pid
populated with the givennode
,id
,serial
, andcreation
. -
.compare(a, b) ⇒ -1, ...
Compares
a
andb
and returns whether they are less than, equal to, or greater than each other.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Return true if
other
has the same type and contents as thisPid
. -
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this
Pid
as a Erlang-readable::String
. -
#inspect ⇒ ::String
The nicely formatted version of the
Pid
.
Instance Attribute Details
#creation ⇒ Integer (readonly)
Return the creation for this Pid
27 28 29 |
# File 'lib/erlang/pid.rb', line 27 def creation @creation end |
#id ⇒ Integer (readonly)
Return the id for this Pid
19 20 21 |
# File 'lib/erlang/pid.rb', line 19 def id @id end |
#node ⇒ Atom (readonly)
Return the node for this Pid
15 16 17 |
# File 'lib/erlang/pid.rb', line 15 def node @node end |
#serial ⇒ Integer (readonly)
Return the serial for this Pid
23 24 25 |
# File 'lib/erlang/pid.rb', line 23 def serial @serial end |
Class Method Details
.[](node, id, serial = 0, creation = 0) ⇒ Pid
Create a new Pid
populated with the given node
, id
, serial
, and creation
.
37 38 39 |
# File 'lib/erlang/pid.rb', line 37 def [](node, id, serial = 0, creation = 0) return new(node, id, serial, creation) end |
.compare(a, b) ⇒ -1, ...
Compares a
and b
and returns whether they are less than,
equal to, or greater than each other.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/erlang/pid.rb', line 48 def compare(a, b) raise ArgumentError, "'a' must be of Erlang::Pid type" unless a.kind_of?(Erlang::Pid) raise ArgumentError, "'b' must be of Erlang::Pid type" unless b.kind_of?(Erlang::Pid) c = Erlang.compare(a.node, b.node) return c if c != 0 c = Erlang.compare(a.id, b.id) return c if c != 0 c = Erlang.compare(a.serial, b.serial) return c if c != 0 c = Erlang.compare(a.creation, b.creation) return c end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Return true if other
has the same type and contents as this Pid
.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/erlang/pid.rb', line 83 def eql?(other) return true if other.equal?(self) if instance_of?(other.class) return !!(node == other.node && id == other.id && serial == other.serial && creation == other.creation) else return !!(Erlang.compare(other, self) == 0) end end |
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this Pid
as a Erlang-readable ::String
.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/erlang/pid.rb', line 103 def erlang_inspect(raw = false) if raw == true and Erlang.respond_to?(:term_to_binary) result = 'erlang:binary_to_term(' result << Erlang.inspect(Erlang.term_to_binary(self), raw: raw) result << ')' return result else return Erlang.inspect(Erlang::Tuple[:pid, node, id, serial, creation], raw: raw) end end |
#inspect ⇒ ::String
Returns the nicely formatted version of the Pid
.
115 116 117 |
# File 'lib/erlang/pid.rb', line 115 def inspect return "Erlang::Pid[#{node.inspect}, #{id.inspect}, #{serial.inspect}, #{creation.inspect}]" end |