From: Kero van Gelder Date: 2003-08-15T06:30:57+09:00 Subject: Re: Exposing C "enums" through extensions On Wed, 13 Aug 2003 13:03:14 +0900, Scott Thompson wrote: > I'm allowing Ruby to access a C based library through an extension. > I'd like to expose some of the enums that are in the C interface, but > wasn't sure about the best way to do this. > > My first thought was to define them as class variables within the > relevant class. But then, as I discovered, there wasn't a good way I > could keep external code from modifying the values of those variables. > It would be really bad if someone set the value of the "miter line > join" constant to 7 when the only valid range of values is 0 - 3. Can you prevent this in C? you'll need to raise an ArgumentError somewhere, I'd say. > On the "Extending Ruby" web site at > , I found the > routine"rb_define_readonly_variable" which sounds pretty good. But, so > far as I can tell, it defines a global variable and my preference would > be to scope the variables inside of a class (I don't know why... it > just seems "tidier"). rb_define_const() should do the trick. also works for #defines. hth, Kero.