Class: Types::String
- Inherits:
-
TypedValue
- Object
- Typed
- TypedValue
- Types::String
- Extended by:
- Forwardable
- Defined in:
- lib/solidity/typed/values.rb
Constant Summary
Constants inherited from Typed
Typed::ADDRESS_ZERO, Typed::BYTES20_ZERO, Typed::BYTES32_ZERO, Typed::BYTES_ZERO, Typed::INSCRIPTION_ID_ZERO, Typed::STRING_ZERO
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
allow compare with “plain” string too - why? why not?.
-
#initialize(initial_value = STRING_ZERO) ⇒ String
constructor
A new instance of String.
-
#to_str ⇒ Object
“automagilally” support implicit string conversion - why? why not?.
- #zero? ⇒ Boolean
Methods inherited from TypedValue
#as_data, #eql?, #hash, #pretty_print, #to_s
Methods inherited from Typed
#as_data, #as_json, dump, serialize, #serialize, #type
Constructor Details
#initialize(initial_value = STRING_ZERO) ⇒ String
Returns a new instance of String.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/solidity/typed/values.rb', line 12 def initialize( initial_value = STRING_ZERO ) ## was: initial_value ||= type.zero ## check if nil gets passed in - default not used? raise ArgumentError, "expected literal of type #{type}; got typed #{initial_value.pretty_print_inspect}" if initial_value.is_a?( Typed ) @value = type.check_and_normalize_literal( initial_value ) @value.freeze ## freeze here - why? why not? @value end |
Class Method Details
.type ⇒ Object
7 |
# File 'lib/solidity/typed/values.rb', line 7 def self.type() StringType.instance; end |
.zero ⇒ Object
8 |
# File 'lib/solidity/typed/values.rb', line 8 def self.zero() @zero ||= new; end |
Instance Method Details
#==(other) ⇒ Object
allow compare with “plain” string too - why? why not?
36 37 38 39 40 41 42 43 44 |
# File 'lib/solidity/typed/values.rb', line 36 def ==(other) if other.is_a?(String) ## typed (frozen) string @value == other.instance_variable_get( :@value ) ## compare value via as_data!!! elsif other.is_a?( ::String ) ## ruby "literal" string @value == other else false end end |
#to_str ⇒ Object
“automagilally” support implicit string conversion - why? why not?
32 |
# File 'lib/solidity/typed/values.rb', line 32 def to_str() @value; end |
#zero? ⇒ Boolean
9 |
# File 'lib/solidity/typed/values.rb', line 9 def zero?() @value.empty?; end |