Class: Erlang::Reference

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

Overview

A Reference is an unique reference.

Creating New References

# New reference
Erlang::Reference["nonode@nohost", 0, [0, 0, 0]]
# => Erlang::Reference[:"nonode@nohost", 0, [0, 0, 0]]
# Old reference
Erlang::Reference["nonode@nohost", 0, 0]
# => Erlang::Reference[:"nonode@nohost", 0, 0]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#creationInteger (readonly)

Return the creation for this Reference

Returns:

  • (Integer)


26
27
28
# File 'lib/erlang/reference.rb', line 26

def creation
  @creation
end

#ids[Integer] (readonly)

Return the ids for this Reference

Returns:

  • ([Integer])


30
31
32
# File 'lib/erlang/reference.rb', line 30

def ids
  @ids
end

#nodeAtom (readonly)

Return the node for this Reference

Returns:



22
23
24
# File 'lib/erlang/reference.rb', line 22

def node
  @node
end

Class Method Details

.[](node, creation, ids) ⇒ Reference

Create a new Reference populated with the given node, creation, and id(s).

Parameters:

  • node (Atom, Symbol)

    The node atom

  • creation (Integer)

    The creation time as a non-negative integer

  • ids (Integer)

    The ids as a List of non-negative integers

Returns:

Raises:

  • (ArgumentError)

    if node is not an Atom or creation or ids are not non-negative Integers



39
40
41
# File 'lib/erlang/reference.rb', line 39

def [](node, creation, ids)
  return new(node, creation, ids)
end

.compare(a, b) ⇒ -1, ...

Compares a and b and returns whether they are less than, equal to, or greater than each other.

Parameters:

Returns:

  • (-1, 0, 1)

Raises:

  • (ArgumentError)

    if a or b is not a Reference



50
51
52
53
54
55
56
57
58
59
# File 'lib/erlang/reference.rb', line 50

def compare(a, b)
  raise ArgumentError, "'a' must be of Erlang::Reference type" unless a.kind_of?(Erlang::Reference)
  raise ArgumentError, "'b' must be of Erlang::Reference type" unless b.kind_of?(Erlang::Reference)
  c = Erlang.compare(a.node, b.node)
  return c if c != 0
  c = Erlang.compare(a.creation, b.creation)
  return c if c != 0
  c = Erlang.compare(a.ids, b.ids)
  return c
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Return true if other has the same type and contents as this Reference.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
# File 'lib/erlang/reference.rb', line 91

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

#erlang_inspect(raw = false) ⇒ ::String

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

Examples:

# New reference
Erlang::Reference["nonode@nohost", 0, [0, 0, 0]].erlang_inspect
# => "{'reference','nonode@nohost',0,[0,0,0]}"
# Old reference
Erlang::Reference["nonode@nohost", 0, 0].erlang_inspect
# => "{'reference','nonode@nohost',0,0}"

Returns:

  • (::String)


131
132
133
134
135
136
137
138
139
140
# File 'lib/erlang/reference.rb', line 131

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[:reference, @node, @creation, @ids], raw: raw)
  end
end

#idInteger

Return the singular id if this Reference is an old reference. Otherwise, raise a NewReferenceError.

Returns:

  • (Integer)

Raises:

  • (NewReferenceError)

    if new reference



108
109
110
111
# File 'lib/erlang/reference.rb', line 108

def id
  raise Erlang::NewReferenceError if new_reference?
  return @ids
end

#inspect::String

Returns the nicely formatted version of the Reference.

Returns:

  • (::String)

    the nicely formatted version of the Reference



143
144
145
# File 'lib/erlang/reference.rb', line 143

def inspect
  return "Erlang::Reference[#{@node.inspect}, #{@creation.inspect}, #{@ids.inspect}]"
end

#new_reference?Boolean

Return true if this is a new reference.

Returns:

  • (Boolean)


116
117
118
# File 'lib/erlang/reference.rb', line 116

def new_reference?
  return Erlang.is_list(@ids)
end