Class: Erlang::Function
- Inherits:
-
Object
- Object
- Erlang::Function
- Defined in:
- lib/erlang/function.rb
Overview
An Function
is an internal function. It corresponds to the fun F/A
and fun(Arg1,...) -> ...
syntax from Erlang.
Creating Functions
Erlang::Function[
arity: 0,
uniq: "c>yRz_\xF6\xED?Hv(\x04\x19\x102",
index: 20,
mod: :erl_eval,
old_index: 20,
old_uniq: 52032458,
pid: Erlang::Pid["nonode@nohost", 79, 0, 0],
free_vars: Erlang::List[
Erlang::Tuple[
Erlang::Nil,
:none,
:none,
Erlang::List[
Erlang::Tuple[
:clause,
27,
Erlang::Nil,
Erlang::Nil,
Erlang::List[Erlang::Tuple[:atom, 0, :ok]]
]
]
]
]
]
Instance Attribute Summary collapse
-
#arity ⇒ Integer
readonly
Return the arity for this
Function
. -
#free_vars ⇒ List
readonly
Return the free variables list for this
Function
. -
#index ⇒ Integer
readonly
Return the index for this
Function
. -
#mod ⇒ Atom
readonly
Return the module for this
Function
. -
#old_index ⇒ Integer
readonly
Return the old index for this
Function
. -
#old_uniq ⇒ Integer
readonly
Return the old uniq for this
Function
. -
#pid ⇒ Pid
readonly
Return the pid for this
Function
. -
#uniq ⇒ Integer
readonly
Return the uniq for this
Function
.
Class Method Summary collapse
-
.[](mod:, free_vars:, pid: nil, arity: nil, uniq: nil, index: nil, old_index: nil, old_uniq: nil) ⇒ Function
Create a new
Function
populated with the given parameters. -
.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 thisFunction
. -
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this
Function
as a Erlang-readable::String
. -
#inspect ⇒ String
The nicely formatted version of the
Function
. -
#new_function? ⇒ Boolean
Return true if this is a new function.
Instance Attribute Details
#arity ⇒ Integer (readonly)
Return the arity for this Function
38 39 40 |
# File 'lib/erlang/function.rb', line 38 def arity @arity end |
#free_vars ⇒ List (readonly)
Return the free variables list for this Function
66 67 68 |
# File 'lib/erlang/function.rb', line 66 def free_vars @free_vars end |
#index ⇒ Integer (readonly)
Return the index for this Function
46 47 48 |
# File 'lib/erlang/function.rb', line 46 def index @index end |
#mod ⇒ Atom (readonly)
Return the module for this Function
50 51 52 |
# File 'lib/erlang/function.rb', line 50 def mod @mod end |
#old_index ⇒ Integer (readonly)
Return the old index for this Function
54 55 56 |
# File 'lib/erlang/function.rb', line 54 def old_index @old_index end |
#old_uniq ⇒ Integer (readonly)
Return the old uniq for this Function
58 59 60 |
# File 'lib/erlang/function.rb', line 58 def old_uniq @old_uniq end |
#pid ⇒ Pid (readonly)
Return the pid for this Function
62 63 64 |
# File 'lib/erlang/function.rb', line 62 def pid @pid end |
#uniq ⇒ Integer (readonly)
Return the uniq for this Function
42 43 44 |
# File 'lib/erlang/function.rb', line 42 def uniq @uniq end |
Class Method Details
.[](mod:, free_vars:, pid: nil, arity: nil, uniq: nil, index: nil, old_index: nil, old_uniq: nil) ⇒ Function
Create a new Function
populated with the given parameters.
80 81 82 |
# File 'lib/erlang/function.rb', line 80 def [](mod:, free_vars:, pid: nil, arity: nil, uniq: nil, index: nil, old_index: nil, old_uniq: nil) return new(mod: mod, free_vars: free_vars, pid: pid, arity: arity, uniq: uniq, index: index, old_index: old_index, old_uniq: old_uniq) end |
.compare(a, b) ⇒ -1, ...
Compares a
and b
and returns whether they are less than,
equal to, or greater than each other.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/erlang/function.rb', line 91 def compare(a, b) return Erlang::Export.compare(a, b) if a.kind_of?(Erlang::Export) and b.kind_of?(Erlang::Export) return -1 if a.kind_of?(Erlang::Function) and b.kind_of?(Erlang::Export) return 1 if b.kind_of?(Erlang::Function) and a.kind_of?(Erlang::Export) raise ArgumentError, "'a' must be of Erlang::Function type" unless a.kind_of?(Erlang::Function) raise ArgumentError, "'b' must be of Erlang::Function type" unless b.kind_of?(Erlang::Function) c = Erlang.compare(a.arity, b.arity) return c if c != 0 c = Erlang.compare(a.uniq, b.uniq) return c if c != 0 c = Erlang.compare(a.index, b.index) return c if c != 0 c = Erlang.compare(a.mod, b.mod) return c if c != 0 c = Erlang.compare(a.old_index, b.old_index) return c if c != 0 c = Erlang.compare(a.old_uniq, b.old_uniq) return c if c != 0 c = Erlang.compare(a.pid, b.pid) return c if c != 0 c = Erlang.compare(a.free_vars, b.free_vars) return c end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Return true if other
has the same type and contents as this Function
.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/erlang/function.rb', line 173 def eql?(other) return true if other.equal?(self) if instance_of?(other.class) return !!(new_function? == other.new_function? && arity == other.arity && uniq == other.uniq && index == other.index && mod == other.mod && old_index == other.old_index && old_uniq == other.old_uniq && pid == other.pid && free_vars == other.free_vars) else return !!(Erlang.compare(other, self) == 0) end end |
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this Function
as a Erlang-readable ::String
.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/erlang/function.rb', line 199 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 if new_function? return Erlang.inspect(Erlang::Tuple[:function, @arity, @uniq, @index, @mod, @old_index, @old_uniq, @pid, @free_vars], raw: raw) else return Erlang.inspect(Erlang::Tuple[:function, @pid, @mod, @index, @uniq, @free_vars], raw: raw) end end end |
#inspect ⇒ String
Returns the nicely formatted version of the Function
.
215 216 217 218 219 220 221 |
# File 'lib/erlang/function.rb', line 215 def inspect if new_function? return "Erlang::Function[arity: #{arity.inspect}, uniq: #{uniq.inspect}, index: #{index.inspect}, mod: #{mod.inspect}, old_index: #{old_index.inspect}, old_uniq: #{old_uniq.inspect}, pid: #{pid.inspect}, free_vars: #{free_vars.inspect}]" else return "Erlang::Function[pid: #{pid.inspect}, mod: #{mod.inspect}, index: #{index.inspect}, uniq: #{uniq.inspect}, free_vars: #{free_vars.inspect}]" end end |
#new_function? ⇒ Boolean
Return true if this is a new function.
165 166 167 |
# File 'lib/erlang/function.rb', line 165 def new_function? return !!(!arity.nil?) end |