Class: Int
Instance Attribute Summary
Attributes inherited from DataType
Instance Method Summary collapse
- #add(other) ⇒ Object
- #as_bool ⇒ Object
- #as_string ⇒ Object
- #div(other) ⇒ Object
- #ge(other) ⇒ Object
- #gt(other) ⇒ Object
-
#initialize(val = nil) ⇒ Int
constructor
A new instance of Int.
- #le(other) ⇒ Object
- #lt(other) ⇒ Object
- #mod(other) ⇒ Object
- #mul(other) ⇒ Object
- #pow(other) ⇒ Object
- #sub(other) ⇒ Object
Constructor Details
#initialize(val = nil) ⇒ Int
Returns a new instance of Int.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sdx/vm/datatypes.rb', line 75 def initialize(val=nil) if val != nil @internal = val end @fields = { "__as_string" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_string" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_bool" => (NativeFnInternal.new (Proc.new do as_bool end)), "__add" => (NativeFnInternal.new (Proc.new do |other| add other[0] end)), "__sub" => (NativeFnInternal.new (Proc.new do |other| sub other[0] end)), "__mul" => (NativeFnInternal.new (Proc.new do |other| mul other[0] end)), "__div" => (NativeFnInternal.new (Proc.new do |other| div other[0] end)), "__mod" => (NativeFnInternal.new (Proc.new do |other| mod other[0] end)), "__pow" => (NativeFnInternal.new (Proc.new do |other| pow other[0] end)), "__lt" => (NativeFnInternal.new (Proc.new do |other| lt other[0] end)), "__gt" => (NativeFnInternal.new (Proc.new do |other| gt other[0] end)), "__le" => (NativeFnInternal.new (Proc.new do |other| le other[0] end)), "__ge" => (NativeFnInternal.new (Proc.new do |other| ge other[0] end)), "__eq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal == other[0].internal end)), "__neq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal != other[0].internal end)) } end |
Instance Method Details
#add(other) ⇒ Object
136 137 138 |
# File 'lib/sdx/vm/datatypes.rb', line 136 def add(other) Int.new @internal + other.internal end |
#as_bool ⇒ Object
132 133 134 |
# File 'lib/sdx/vm/datatypes.rb', line 132 def as_bool Bool.new true end |
#as_string ⇒ Object
128 129 130 |
# File 'lib/sdx/vm/datatypes.rb', line 128 def as_string Str.new @internal.to_s end |
#div(other) ⇒ Object
148 149 150 |
# File 'lib/sdx/vm/datatypes.rb', line 148 def div(other) Int.new @internal / other.internal end |
#ge(other) ⇒ Object
172 173 174 |
# File 'lib/sdx/vm/datatypes.rb', line 172 def ge(other) Bool.new @internal >= other.internal end |
#gt(other) ⇒ Object
164 165 166 |
# File 'lib/sdx/vm/datatypes.rb', line 164 def gt(other) Bool.new @internal > other.internal end |
#le(other) ⇒ Object
168 169 170 |
# File 'lib/sdx/vm/datatypes.rb', line 168 def le(other) Bool.new @internal <= other.internal end |
#lt(other) ⇒ Object
160 161 162 |
# File 'lib/sdx/vm/datatypes.rb', line 160 def lt(other) Bool.new @internal < other.internal end |
#mod(other) ⇒ Object
152 153 154 |
# File 'lib/sdx/vm/datatypes.rb', line 152 def mod(other) Int.new @internal % other.internal end |
#mul(other) ⇒ Object
144 145 146 |
# File 'lib/sdx/vm/datatypes.rb', line 144 def mul(other) Int.new @internal * other.internal end |
#pow(other) ⇒ Object
156 157 158 |
# File 'lib/sdx/vm/datatypes.rb', line 156 def pow(other) Int.new @internal ** other.internal end |
#sub(other) ⇒ Object
140 141 142 |
# File 'lib/sdx/vm/datatypes.rb', line 140 def sub(other) Int.new @internal - other.internal end |