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
Sorry, ruby-forum cut off the rest of what I wrote. The above code
example is doing the first way for both 1.8 and 1.9. What’s the proper
way to detect the ruby version or the feature?
version.h couldn’t be found. I’ve read that version.h is deprecated in
Ruby 1.9. There’s either got to be another way to detect the change or
a way to work around it. I’d just use map! to convert the strings to
symbols if I knew how to do it in C.
version.h couldn’t be found. I’ve read that version.h is deprecated in
Ruby 1.9. There’s either got to be another way to detect the change or
a way to work around it. I’d just use map! to convert the strings to
symbols if I knew how to do it in C.
I’m not saying this is the best way (maybe Nobu can provide a better
answer), but if you can be sure that mkmf.rb is being executed by the
same version of Ruby, then you could cook up a feature test in your
extconf.rb that would create a preprocessor symbol to test. Determine
what singleton_methods is doing, then call $defs.push to set a symbol:
At Fri, 20 Feb 2009 02:21:24 +0900,
Jason G. wrote in [ruby-talk:328775]:
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:
The output? You convert the argument.
#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
And #singleton_methods takes a flag, anything not only string
and symbol can be true.
At Fri, 20 Feb 2009 18:58:55 +0900,
Jason G. wrote in [ruby-talk:328856]:
Sorry, nobu, I didn’t follow you. Try again?
Sorry, I misread the parentheses.
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:
It’s a problem indeed.
#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
Do you really need to know only if singleton method is defined,
not just self responds to it?
I ended up sidestepping the whole issue completely and writing a new
accessor, #formatter_methods, that just returned singleton_methods.map!
{|method| method.to_sym }. The reasons for needing #singleton_methods
and not #respond_to? or #method_defined? are hard to explain, but you
can probably understand it fairly quickly by looking at the source:
A macro would’ve been nice, but it worked out okay for me anyway.
Thanks for your help!