Class: Erlang::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/erlang/port.rb

Overview

A Port is a port object obtained from erlang:open_port/2.

Creating Ports

Erlang::Port["nonode@nohost", 100, 1]
# => Erlang::Port[:"nonode@nohost", 100, 1]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#creationInteger (readonly)

Return the creation for this Port

Returns:

  • (Integer)


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

def creation
  @creation
end

#idInteger (readonly)

Return the id for this Port

Returns:

  • (Integer)


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

def id
  @id
end

#nodeAtom (readonly)

Return the node for this Port

Returns:



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

def node
  @node
end

Class Method Details

.[](node, id, creation = 0) ⇒ Port

Create a new Port populated with the given node, id, and creation.

Parameters:

  • node (Atom, Symbol)

    The node atom

  • id (Integer)

    The id 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 id or creation are not non-negative Integers



32
33
34
# File 'lib/erlang/port.rb', line 32

def [](node, id, creation = 0)
  return new(node, id, 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 (Port)

    The left argument

  • b (Port)

    The right argument

Returns:

  • (-1, 0, 1)

Raises:

  • (ArgumentError)

    if a or b is not a Port



43
44
45
46
47
48
49
50
51
52
# File 'lib/erlang/port.rb', line 43

def compare(a, b)
  raise ArgumentError, "'a' must be of Erlang::Port type" unless a.kind_of?(Erlang::Port)
  raise ArgumentError, "'b' must be of Erlang::Port type" unless b.kind_of?(Erlang::Port)
  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.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 Port.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
# File 'lib/erlang/port.rb', line 74

def eql?(other)
  return true if other.equal?(self)
  if instance_of?(other.class)
    return !!(node == other.node &&
      id == other.id &&
      creation == other.creation)
  else
    return !!(Erlang.compare(other, self) == 0)
  end
end

#erlang_inspect(raw = false) ⇒ ::String

Return the contents of this Port as a Erlang-readable ::String.

Examples:

Erlang::Port["nonode@nohost", 100, 1].erlang_inspect
# => "{'port','nonode@nohost',100,1}"

Returns:

  • (::String)


93
94
95
96
97
98
99
100
101
102
# File 'lib/erlang/port.rb', line 93

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[:port, node, id, creation], raw: raw)
  end
end

#inspect::String

Returns the nicely formatted version of the Port.

Returns:

  • (::String)

    the nicely formatted version of the Port.



105
106
107
# File 'lib/erlang/port.rb', line 105

def inspect
  return "Erlang::Port[#{node.inspect}, #{id.inspect}, #{creation.inspect}]"
end