Class: Erlang::Pid

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#creationInteger (readonly)

Return the creation for this Pid

Returns:

  • (Integer)


27
28
29
# File 'lib/erlang/pid.rb', line 27

def creation
  @creation
end

#idInteger (readonly)

Return the id for this Pid

Returns:

  • (Integer)


19
20
21
# File 'lib/erlang/pid.rb', line 19

def id
  @id
end

#nodeAtom (readonly)

Return the node for this Pid

Returns:



15
16
17
# File 'lib/erlang/pid.rb', line 15

def node
  @node
end

#serialInteger (readonly)

Return the serial for this Pid

Returns:

  • (Integer)


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.

Parameters:

  • node (Atom, Symbol)

    The node atom

  • id (Integer)

    The id as a non-negative integer

  • serial (Integer) (defaults to: 0)

    The serial time as a non-negative integer

  • creation (Integer) (defaults to: 0)

    The creation time as a non-negative integer

Returns:

Raises:

  • (ArgumentError)

    if node is not an Atom or one of id, serial, or creation are not non-negative Integers



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.

Parameters:

  • a (Pid)

    The left argument

  • b (Pid)

    The right argument

Returns:

  • (-1, 0, 1)

Raises:

  • (ArgumentError)

    if a or b is not a Pid



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.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)


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.

Examples:

Erlang::Pid["nonode@nohost", 38, 0, 0].erlang_inspect
# => "{'pid','nonode@nohost',38,0,0}"

Returns:

  • (::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.

Returns:

  • (::String)

    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