Class: Erlang::String
- Inherits:
-
Object
- Object
- Erlang::String
- Defined in:
- lib/erlang/string.rb
Overview
Instance Attribute Summary collapse
-
#data ⇒ ::String
readonly
Return the data for this
String
.
Class Method Summary collapse
-
.[](*data) ⇒ String
Create a new
String
populated with the givendata
. -
.compare(a, b) ⇒ -1, ...
Compares
a
andb
and returns whether they are less than, equal to, or greater than each other. -
.empty ⇒ String
Return an empty
String
.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns true if this
String
is empty. -
#eql?(other) ⇒ Boolean
(also: #==)
Return true if
other
has the same type and contents as thisString
. -
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this
String
as a Erlang-readable::String
. -
#flatten ⇒ [::String]
Returns an
::Array
with the::String
data for thisString
. -
#inspect ⇒ ::String
The nicely formatted version of the
String
. -
#length ⇒ Integer
(also: #size)
Returns the length of this
String
. -
#to_atom ⇒ Atom
The
Atom
version of theString
. -
#to_binary ⇒ Binary
The
Binary
version of theString
. -
#to_list ⇒ List
The
List
version of theString
. -
#to_s ⇒ ::String
(also: #to_str)
The string version of the
String
. -
#to_string ⇒ self
The
String
version of theString
.
Instance Attribute Details
#data ⇒ ::String (readonly)
Return the data for this String
20 21 22 |
# File 'lib/erlang/string.rb', line 20 def data @data end |
Class Method Details
.[](*data) ⇒ String
Create a new String
populated with the given data
.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/erlang/string.rb', line 27 def [](*data) return EmptyString if data.empty? if data.size == 1 return data[0] if data[0].kind_of?(Erlang::String) end unless data.is_a?(::String) data = Erlang.iolist_to_binary(data).data end return new(data) end |
.compare(a, b) ⇒ -1, ...
Compares a
and b
and returns whether they are less than,
equal to, or greater than each other.
53 54 55 56 57 58 59 |
# File 'lib/erlang/string.rb', line 53 def compare(a, b) raise ArgumentError, "'a' must be of Erlang::String type" if not a.kind_of?(Erlang::String) raise ArgumentError, "'b' must be of Erlang::String type" if not b.kind_of?(Erlang::String) c = a.size <=> b.size return a.data <=> b.data if c == 0 return Erlang::List.compare(a.to_list, b.to_list) end |
.empty ⇒ String
Return an empty String
. If used on a subclass, returns an empty instance
of that class.
42 43 44 |
# File 'lib/erlang/string.rb', line 42 def empty return @empty ||= self.new end |
Instance Method Details
#empty? ⇒ Boolean
Returns true if this String
is empty.
77 78 79 |
# File 'lib/erlang/string.rb', line 77 def empty? return @data.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
Return true if other
has the same type and contents as this String
.
100 101 102 103 104 105 106 107 |
# File 'lib/erlang/string.rb', line 100 def eql?(other) return true if other.equal?(self) if instance_of?(other.class) return !!(self.class.compare(self, other) == 0) else return !!(Erlang.compare(other, self) == 0) end end |
#erlang_inspect(raw = false) ⇒ ::String
Return the contents of this String
as a Erlang-readable ::String
.
120 121 122 123 124 125 126 |
# File 'lib/erlang/string.rb', line 120 def erlang_inspect(raw = false) if raw == false return @data.inspect else return '[' << @data.bytes.join(',') << ']' end end |
#flatten ⇒ [::String]
Returns an ::Array
with the ::String
data for this String
.
84 85 86 |
# File 'lib/erlang/string.rb', line 84 def flatten return [@data] end |
#inspect ⇒ ::String
Returns the nicely formatted version of the String
.
129 130 131 |
# File 'lib/erlang/string.rb', line 129 def inspect return "Erlang::String[#{@data.inspect}]" end |
#length ⇒ Integer Also known as: size
Returns the length of this String
.
91 92 93 |
# File 'lib/erlang/string.rb', line 91 def length return @data.bytesize end |
#to_atom ⇒ Atom
Returns the Atom
version of the String
.
134 135 136 |
# File 'lib/erlang/string.rb', line 134 def to_atom return Erlang::Atom[@data] end |
#to_binary ⇒ Binary
Returns the Binary
version of the String
.
139 140 141 |
# File 'lib/erlang/string.rb', line 139 def to_binary return Erlang::Binary[@data] end |
#to_list ⇒ List
Returns the List
version of the String
.
144 145 146 |
# File 'lib/erlang/string.rb', line 144 def to_list return Erlang::List.from_enum(@data.bytes) end |
#to_s ⇒ ::String Also known as: to_str
Returns the string version of the String
.
154 155 156 |
# File 'lib/erlang/string.rb', line 154 def to_s return @data end |
#to_string ⇒ self
Returns the String
version of the String
.
149 150 151 |
# File 'lib/erlang/string.rb', line 149 def to_string return self end |