Class: Erlang::Export

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

Overview

An Export is an external function. It corresponds to the fun M:F/A syntax from Erlang.

Creating Exports

Erlang::Export[:erlang, :make_ref, 0]
# => Erlang::Export[:erlang, :make_ref, 0]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arityInteger (readonly)

Return the arity for this Export

Returns:

  • (Integer)


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

def arity
  @arity
end

#functionAtom (readonly)

Return the function for this Export

Returns:



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

def function
  @function
end

#modAtom (readonly)

Return the module for this Export

Returns:



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

def mod
  @mod
end

Class Method Details

.[](mod, function, arity) ⇒ Export

Create a new Export populated with the given mod, function, and arity.

Parameters:

  • mod (Atom, Symbol)

    The module atom

  • function (Atom, Symbol)

    The function atom

  • arity (Integer)

    The arity of the function

Returns:

Raises:

  • (ArgumentError)

    if arity is not an Integer



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

def [](mod, function, arity)
  return new(mod, function, arity)
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 (Export)

    The left argument

  • b (Export)

    The right argument

Returns:

  • (-1, 0, 1)

Raises:

  • (ArgumentError)

    if a or b is not an Export



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

def compare(a, b)
  raise ArgumentError, "'a' must be of Erlang::Export type" unless a.kind_of?(Erlang::Export)
  raise ArgumentError, "'b' must be of Erlang::Export type" unless b.kind_of?(Erlang::Export)
  c = Erlang.compare(a.mod, b.mod)
  return c if c != 0
  c = Erlang.compare(a.function, b.function)
  return c if c != 0
  c = Erlang.compare(a.arity, b.arity)
  return c
end

Instance Method Details

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

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

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
# File 'lib/erlang/export.rb', line 67

def eql?(other)
  return true if other.equal?(self)
  if instance_of?(other.class)
    return !!(mod == other.mod &&
      function == other.function &&
      arity == other.arity)
  else
    return !!(Erlang.compare(other, self) == 0)
  end
end

#erlang_inspect(raw = false) ⇒ ::String

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

Examples:

Erlang::Export[:erlang, :make_ref, 0].erlang_inspect
# => "fun 'erlang':'make_ref'/0"

Returns:

  • (::String)


86
87
88
89
90
91
92
93
94
# File 'lib/erlang/export.rb', line 86

def erlang_inspect(raw = false)
  result = 'fun '
  result << Erlang.inspect(@mod, raw: raw)
  result << ':'
  result << Erlang.inspect(@function, raw: raw)
  result << '/'
  result << Erlang.inspect(@arity, raw: raw)
  return result
end

#inspect::String

Returns the nicely formatted version of the Export.

Returns:

  • (::String)

    the nicely formatted version of the Export.



97
98
99
# File 'lib/erlang/export.rb', line 97

def inspect
  return "Erlang::Export[#{mod.inspect}, #{function.inspect}, #{arity.inspect}]"
end