------ art_40748_21383597.1187139852136 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/14/07, Zhan feng Wang <wzfg / singtel.com> wrote: > > 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 >1,second byte give tag_no base > 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? > > Which document specified this? > Thanks > -- > Posted via http://www.ruby-forum.com/. > > ------ art_40748_21383597.1187139852136--