[Note: parts of this message were removed to make it a legal post.]
I'm working on updating RedCloth for Ruby 1.9. Since the output of
#singleton_methods changed from strings to symbols, I think I need a
conditional compile. Here's what I tried:
#if RUBY_VERSION < 0x10900
if (rb_ary_includes(rb_funcall(self, rb_intern("singleton_methods"),
0), btype)) {
#else
if (rb_ary_includes(rb_funcall(self, rb_intern("singleton_methods"),
0), rb_str_intern(btype))) {
#endif
from version.h in Ruby 1.9
define RUBY_VERSION "1.9.2"
#define RUBY_RELEASE_DATE "2009-02-16"
#define RUBY_PATCHLEVEL -1
#define RUBY_BRANCH_NAME "trunk"
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_YEAR 2009
#define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 16
and for Ruby 1.8.6
#define RUBY_VERSION "1.8.6"
#define RUBY_RELEASE_DATE "2007-11-12"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20071112
#define RUBY_PATCHLEVEL 5000
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 11
#define RUBY_RELEASE_DAY 12
so I think that you want something like
#if RUBY_VERSION < '1.9.0'
do pre 1.9 stuff
#else
do 1.9 stuff
#end
Matz is careful to use Ruby version numbers which can be compared using
string comparison.
or
#if RUBY_VERSION_MAJOR = 1 && RUBY_VERSION_MINOR == 9
do 1.9 stuff
#else
do 1.8 stuff
#end
or some variant on those.
--
Rick DeNatale
Blog:
http://talklikeaduck.denhaven2.com/
Twitter:
http://twitter.com/RickDeNatale
WWR:
http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn:
http://www.linkedin.com/in/rickdenatale