Reputation: 23
In c++ you can do:
uint8 foo_bar
How would we do the same thing in ruby? Any alternatives?
This post seems close to it maybe someone can explain?
Upvotes: 2
Views: 5459
Reputation: 74945
Ruby abstracts away the internal storage of integers, so you don't have to worry about it.
If you assign an integer to a variable, Ruby will deal with the internals, allocating memory when needed. Smaller integers are of type Fixnum
(stored in a single word), larger integers are of type Bignum
.
a = 64
a.class #=> Fixnum; stored in a single word
a += 1234567890
a.class #=> Bignum; stored in more than a single word
Ruby is dynamically typed, so you cannot force a variable to contain only unsigned 8-bit integers (just as you cannot force a variable to only contain string values, etc.).
Upvotes: 11
Reputation: 2367
You don't declare types in Ruby. The language is dynamically typed.
Upvotes: 0