Class: Erlang::Reference
- Inherits:
-
Object
- Object
- Erlang::Reference
- 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
-
#creation ⇒ Integer
readonly
Return the creation for this
Reference
. -
#ids ⇒ [Integer]
readonly
Return the ids for this
Reference
. -
#node ⇒ Atom
readonly
Return the node for this
Reference
.
Class Method Summary collapse
-
.[](node, creation, ids) ⇒ Reference
Create a new
Reference
populated with the given node, creation, and id(s). -
.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 thisReference
. -
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this
reference
as a Erlang-readable::String
. -
#id ⇒ Integer
Return the singular id if this
Reference
is an old reference. -
#inspect ⇒ ::String
The nicely formatted version of the
Reference
. -
#new_reference? ⇒ Boolean
Return true if this is a new reference.
Instance Attribute Details
#creation ⇒ Integer (readonly)
Return the creation for this Reference
26 27 28 |
# File 'lib/erlang/reference.rb', line 26 def creation @creation end |
#ids ⇒ [Integer] (readonly)
Return the ids for this Reference
30 31 32 |
# File 'lib/erlang/reference.rb', line 30 def ids @ids end |
#node ⇒ Atom (readonly)
Return the node for this Reference
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).
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.
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
.
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
.
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 |
#id ⇒ Integer
Return the singular id if this Reference
is an old
reference. Otherwise, raise a NewReferenceError
.
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
.
143 144 145 |
# File 'lib/erlang/reference.rb', line 143 def inspect return "Erlang::Reference[#{@node.inspect}, #{@creation.inspect}, #{@ids.inspect}]" end |