Daniel Scher wrote:
> Alex Fenton wrote:
>> In C extension code, what's the canonical way to test whether the ruby  
>> being compiled against is 1.8 or 1.9?
>> [...]
>> But this seems accidental. However I didn't find a RUBY_VERSION constant  
>> in the headers anywhere.
>> [...]
> 
> Have you looked at version.h?
> 
> # head -n12 ruby-1.9-svn/version.h
> #define RUBY_VERSION "1.9.0"
> #define RUBY_RELEASE_DATE "2008-11-10"
> #define RUBY_VERSION_CODE 190
> #define RUBY_RELEASE_CODE 20081110
> #define RUBY_PATCHLEVEL 0


Thanks, this looked perfect. I wondered why my 'grep VERSION 
include/ruby/*.h' hadn't found this. Turns out version.h is deliberately 
not installed for ruby 1.9, although it is in the source tree:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/12069

So the correct way is apparently never to test version, but presence of 
features. In my case I ended up doing

#ifdef HAVE_RUBY_IO_H
#include "ruby/io.h"
#else
#include "rubyio.h"
#endif

to get around the disappearance of the latter header in 1.9.1.

thanks
a