I'm quite new to Ruby, but when I was searching the documentation of Ruby, I found some C source code too which was included in the documentation. In almost all of those references, I found the VALUE
and I'm quite sure its a struct
. But what are the attributes of this VALUE struct
and what is this actually doing?
You can see the definition for VALUE
in the header file ruby/include/ruby/internal/value.h
:
#if defined HAVE_UINTPTR_T && 0
typedef uintptr_t VALUE;
...
#elif SIZEOF_LONG == SIZEOF_VOIDP
typedef unsigned long VALUE;
...
#else
# error
#endif
So value is just a pointer to an object. As described in Priti's link, there is a TYPE()
macro in the same file that can be used to identify the type of data pointed to by a VALUE
.
In C, variables have types and data do not have types. In contrast, Ruby variables do not have a static type, and data themselves have types, so data will need to be converted between the languages.
Data in Ruby are represented by the C type `VALUE'. Each VALUE data has its data-type.
To retrieve C data from a VALUE, you need to:
1. Identify the VALUE's data type
2. Convert the VALUE into C data
For more information look here: Basic Knowledge
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