Class: EncodeM::String
- Inherits:
-
Object
- Object
- EncodeM::String
- Includes:
- Comparable
- Defined in:
- lib/encode_m/string.rb
Instance Attribute Summary collapse
-
#encoded ⇒ Object
readonly
Returns the value of attribute encoded.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison operations.
- #==(other) ⇒ Object (also: #eql?)
-
#empty? ⇒ Boolean
String-specific predicates.
- #hash ⇒ Object
-
#initialize(value) ⇒ String
constructor
A new instance of String.
- #inspect ⇒ Object
- #length ⇒ Object
- #to_encoded ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ String
Returns a new instance of String.
8 9 10 11 |
# File 'lib/encode_m/string.rb', line 8 def initialize(value) @value = value.to_s @encoded = encode_string(@value) end |
Instance Attribute Details
#encoded ⇒ Object (readonly)
Returns the value of attribute encoded.
6 7 8 |
# File 'lib/encode_m/string.rb', line 6 def encoded @encoded end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/encode_m/string.rb', line 6 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison operations
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/encode_m/string.rb', line 35 def <=>(other) case other when EncodeM::String @encoded <=> other.encoded when EncodeM::Numeric 1 # Strings always sort after numbers in M language when EncodeM::Composite # Let Composite handle the comparison -(other <=> self) else nil end end |
#==(other) ⇒ Object Also known as: eql?
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/encode_m/string.rb', line 49 def ==(other) case other when EncodeM::String @value == other.value when ::String @value == other else false end end |
#empty? ⇒ Boolean
String-specific predicates
26 27 28 |
# File 'lib/encode_m/string.rb', line 26 def empty? @value.empty? end |
#hash ⇒ Object
62 63 64 |
# File 'lib/encode_m/string.rb', line 62 def hash @value.hash end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/encode_m/string.rb', line 21 def inspect "EncodeM::String(#{@value.inspect})" end |
#length ⇒ Object
30 31 32 |
# File 'lib/encode_m/string.rb', line 30 def length @value.length end |
#to_encoded ⇒ Object
17 18 19 |
# File 'lib/encode_m/string.rb', line 17 def to_encoded @encoded end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/encode_m/string.rb', line 13 def to_s @value end |