From: Florian Frank Date: 2009-10-03T16:46:54+09:00 Subject: Re: Having a gem for 1.8 and 1.9 (RK) Sentinel wrote: > Rick Denatale wrote: > >> 1.8 vs 1.9 because of the differences in Strings, but I've been able >> to conditionally select which implementation of a few methods get >> "compiled" by testing the ruby version inline. >> >> -- >> Rick DeNatale >> > > Could you give me a snippet of your conditional selection ? > Here's a small example: http://github.com/flori/bullshit/blob/master/lib/bullshit.rb#L716 The code defines a log_gamma function: In 1.8 it uses its own Lanczos approximation algorithm written in Ruby. In 1.9 Math already defines an lgamma method with a complex result and a C-implementation which is used instead if the lgamma method is defined there. If possible it's better to check for features you want to use from a specicific Ruby version instead of checking for the version itself. This way you are prepared if things change or features are eventually backported from Ruby 1.9. -- Florian Frank