Class: Types::Timestamp

Inherits:
TypedValue show all
Includes:
Comparable
Defined in:
lib/solidity/typed/numbers.rb

Constant Summary

Constants inherited from Typed

Types::Typed::ADDRESS_ZERO, Types::Typed::BYTES20_ZERO, Types::Typed::BYTES32_ZERO, Types::Typed::BYTES_ZERO, Types::Typed::INSCRIPTION_ID_ZERO, Types::Typed::STRING_ZERO

Class Method Summary collapse

Instance Method Summary collapse

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 = 0) ⇒ Timestamp

Returns a new instance of Timestamp.

Raises:

  • (ArgumentError)


78
79
80
81
82
83
84
85
86
87
# File 'lib/solidity/typed/numbers.rb', line 78

def initialize( initial_value = 0 )
   ## 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 (and freeze self!) - why? why not?
   @value
end

Class Method Details

.typeObject



74
# File 'lib/solidity/typed/numbers.rb', line 74

def self.type() TimestampType.instance; end

.zeroObject



75
# File 'lib/solidity/typed/numbers.rb', line 75

def self.zero() @zero ||= new; end

Instance Method Details

#+(other) ⇒ Object



93
# File 'lib/solidity/typed/numbers.rb', line 93

def +(other) Timestamp.new( @value + other.to_int); end

#-(other) ⇒ Object



94
# File 'lib/solidity/typed/numbers.rb', line 94

def -(other)  Timestamp.new( @value - other.to_int); end

#<=>(other) ⇒ Object



91
# File 'lib/solidity/typed/numbers.rb', line 91

def <=>(other)  @value <=> other.to_int; end

#to_intObject

“automagilally” support implicit integer conversion - why? why not?



96
# File 'lib/solidity/typed/numbers.rb', line 96

def to_int() @value; end

#zero?Boolean

Returns:

  • (Boolean)


76
# File 'lib/solidity/typed/numbers.rb', line 76

def zero?()  @value == 0; end