Class: Types::UInt

Inherits:
TypedValue show all
Includes:
Comparable
Defined in:
lib/solidity/typed/numbers.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

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) ⇒ UInt

Returns a new instance of UInt.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/solidity/typed/numbers.rb', line 9

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



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

def self.type() UIntType.instance; end

.zeroObject



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

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

Instance Method Details

#*(other) ⇒ Object



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

def *(other)  UInt.new( @value * other.to_int); end

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#/(other) ⇒ Object



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

def /(other)  UInt.new( @value / other.to_int); end

#<=>(other) ⇒ Object



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

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

#div(other) ⇒ Object



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

def div(other) UInt.new( @value.div(other.to_int)); end

#to_iObject



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

def to_i() @value; end

#to_intObject

def to_i() @value; end



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

def to_int() @value; end

#zero?Boolean

Returns:

  • (Boolean)


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

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