From: Gregory Brown Date: 2008-08-08T12:40:18+09:00 Subject: Re: State of Ruby 1.8.6? On Thu, Aug 7, 2008 at 11:27 PM, David Masover wrote: > On Thursday 07 August 2008 12:07:38 Gregory Brown wrote: > >> So if I write my code >> against 1.8.7, my users need to upgrade. > > I guess it depends how much is really different in 1.8.7. For example, I > really, really like Object#tap -- started using it in 1.9, and I see it's now > in 1.8.7. But at work, we use 1.8.6. My solution: > > unless Object.new.respond_to? :tap > Object.class_eval do > def tap > yield self > self > end > end > end > > The "unless" is because, of course, both 1.8.7 and 1.9 write this method in C, > and I assume their version is faster than mine. Yes, and this works fine for internal code. Releasing this sort of stuff is sub-optimal, as you are then risking competing with the N other libraries trying to do the same thing. Though with luck, conflicts won't occur, but it wouldn't surprise me at all if people miss edge cases when they try to implement upcoming Ruby features on their own. That having been said, we do this for a couple features in Prawn, to ensure backwards compatibility from 1.9 to 1.8.x It feels nasty, but since these things are centrally located in a prawn/compatibility.rb file, it'd be a one line patch to disable them. If people doing these sort of tricks, I definitely recommend this approach of keeping your modifications separated out cleanly, so it's easy to work around them. -greg