Class: Types::Int
- 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) ⇒ Int
Returns a new instance of Int.
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/solidity/typed/numbers.rb', line 47
def initialize( initial_value = 0 )
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 @value
end
|
Class Method Details
.type ⇒ Object
43
|
# File 'lib/solidity/typed/numbers.rb', line 43
def self.type() IntType.instance; end
|
.zero ⇒ Object
44
|
# File 'lib/solidity/typed/numbers.rb', line 44
def self.zero() @zero ||= Int.new; end
|
Instance Method Details
#*(other) ⇒ Object
63
|
# File 'lib/solidity/typed/numbers.rb', line 63
def *(other) Int.new( @value * other.to_int); end
|
#+(other) ⇒ Object
61
|
# File 'lib/solidity/typed/numbers.rb', line 61
def +(other ) Int.new( @value + other.to_int); end
|
#-(other) ⇒ Object
62
|
# File 'lib/solidity/typed/numbers.rb', line 62
def -(other) Int.new( @value - other.to_int); end
|
#/(other) ⇒ Object
64
|
# File 'lib/solidity/typed/numbers.rb', line 64
def /(other) Int.new( @value / other.to_int); end
|
#<=>(other) ⇒ Object
59
|
# File 'lib/solidity/typed/numbers.rb', line 59
def <=>(other) @value <=> other.to_int; end
|
#to_i ⇒ Object
68
|
# File 'lib/solidity/typed/numbers.rb', line 68
def to_i() @value; end
|
#to_int ⇒ Object
“automagilally” support implicit integer conversion - why? why not?
67
|
# File 'lib/solidity/typed/numbers.rb', line 67
def to_int() @value; end
|
#zero? ⇒ Boolean
45
|
# File 'lib/solidity/typed/numbers.rb', line 45
def zero?() @value == 0; end
|