Includes simple immutable classes that represent Erlang's atom, binary, bitstring, compressed, export, function, list, map, nil, pid, port, reference, string, and tuple.
Add this line to your application's Gemfile:
gem 'erlang-terms', '~> 2.0'
And then execute:
$ bundle
Or install it yourself as:
$ gem install erlang-terms
The following classes show the Erlang representation followed by the corresponding Ruby representation.
See erlang-etf for more information.
Atom = 'test',
AtomUTF8 = 'Ω'.
atom = Erlang::Atom[:test]
# => :test
atom_utf8 = Erlang::Atom[:Ω, utf8: true]
# => Erlang::Atom["Ω", utf8: true]
Binary0 = <<>>,
Binary1 = <<"test">>,
Binary2 = <<0,1,2>>.
binary0 = Erlang::Binary[]
# => ""
binary1 = Erlang::Binary["test"]
# => "test"
binary2 = Erlang::Binary[0,1,2]
# => "\x00\x01\x02"
Bitstring0 = <<1:7>>,
Bitstring1 = <<"test",2:3>>.
bitstring0 = Erlang::Bitstring[1, bits: 7]
# => Erlang::Bitstring[1, bits: 7]
bitstring1 = Erlang::Bitstring["test", 2, bits: 3]
# => Erlang::Bitstring[116, 101, 115, 116, 2, bits: 3]
Module = erlang,
Function = now,
Arity = 0,
Export = fun Module:Function/Arity.
export = Erlang::Export[:erlang, :now, 0]
# => Erlang::Export[:erlang, :now, 0]
Float = 1.0e12.
float = Erlang::Float[1.0e12]
# => 1.00000000000000000000e+12
List = [a | b].
list = Erlang::List[:a] + :b
# => Erlang::List[:a] + :b
list.improper?
# => true
List = [a, b].
list = Erlang::List[:a, :b]
# => [:a, :b]
list.improper?
# => false
Map = #{atom => 1}.
map = Erlang::Map[:atom, 1]
# => {:atom => 1}
Nil = [].
erlang_nil = Erlang::Nil
# => []
Pid = self().
%% or
Id = 100,
Serial = 5,
Pid = pid(0, Id, Serial).
%% or
Pid = list_to_pid("<0.100.5>").
pid = Erlang::Pid[:"node@host", 100, 5, 0]
# => Erlang::Pid[:"node@host", 100, 5, 0]
Port = hd(erlang:ports()).
port = Erlang::Port[:"nonode@nohost", 0, 0]
# => Erlang::Port[:"nonode@nohost", 0, 0]
Reference = erlang:make_ref().
reference = Erlang::Reference[:"nonode@nohost", 0, [168, 2, 0]]
# => Erlang::Reference[:"nonode@nohost", 0, [168, 2, 0]]
String = "test".
string = Erlang::String["test"]
# => Erlang::String["test"]
Tuple = {atom, 1}.
tuple = Erlang::Tuple[:atom, 1]
# => Erlang::Tuple[:atom, 1]
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request