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.
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/solidity/typed/numbers.rb', line 45
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
41
|
# File 'lib/solidity/typed/numbers.rb', line 41
def self.type() IntType.instance; end
|
.zero ⇒ Object
42
|
# File 'lib/solidity/typed/numbers.rb', line 42
def self.zero() @zero ||= Int.new; end
|
Instance Method Details
#*(other) ⇒ Object
61
|
# File 'lib/solidity/typed/numbers.rb', line 61
def *(other) Int.new( @value * other.to_int); end
|
#+(other) ⇒ Object
59
|
# File 'lib/solidity/typed/numbers.rb', line 59
def +(other ) Int.new( @value + other.to_int); end
|
#-(other) ⇒ Object
60
|
# File 'lib/solidity/typed/numbers.rb', line 60
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
57
|
# File 'lib/solidity/typed/numbers.rb', line 57
def <=>(other) @value <=> other.to_int; end
|
#to_i ⇒ Object
66
|
# File 'lib/solidity/typed/numbers.rb', line 66
def to_i() @value; end
|
#to_int ⇒ Object
“automagilally” support implicit integer conversion - why? why not?
65
|
# File 'lib/solidity/typed/numbers.rb', line 65
def to_int() @value; end
|
#zero? ⇒ Boolean
43
|
# File 'lib/solidity/typed/numbers.rb', line 43
def zero?() @value == 0; end
|