Hi,friends,
I’d like to know how can I define UNION in ruby?
e.g.
In C, I have a UNION as following:
union ID_OCT{
struct ID_BIT{
unsigned class:2; /b8,b7/
unsigned if_prim:1; /b6,0–primitive/
unsigned tag_no:5;/if >=31,second byte give tag_no base
128/
}id;
unsigned char c;
}rid;
How can I define this in Ruby?
Which document specified this?
Thanks
On 8/14/07, Zhan feng Wang [email protected] wrote:
128*/
}id;
unsigned char c;
}rid;
Ruby has no union construct. Depending on what you are trying to
achieve,
there are various options. If you want a union because you need a
variable
to be able to have values of different types, then you need do nothing
special since ruby is dynamically typed. If you want a union because
you’d
like to have mutiple “views” of the same sequence of bytes or bits,
check
out Array#pack and String#unpack, as well as bitstruct
http://raa.ruby-lang.org/project/bit-struct/
How can I define this in Ruby?