I think Ruby is interpreted to C. If so, how can I use the concept of pointers and other features that are parts of C environment? How can we utilize the power of C with the simplicity of Ruby?
In `ruby`, the body of an object is expressed by a struct and always handled via a pointer. A different struct type is used for each class, but the pointer type will always be `VALUE` (figure 1). In practice, when using a `VALUE`, we cast it to the pointer to each object struct.
In Ruby, (almost) every variable is in fact a reference/pointer to an object, e.g.
a = [0, 1, 23] b = a a << 42 p b
will give [0, 1, 23, 42]
because a
and b
are pointing to the same object.
So in fact, you are using pointers all the time.
If you want to do pointer arithmetic as in C, this is not possible with Ruby.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With