a work on process

Making Time#to_date public in Ruby 1.8.6

You are reading a post by James Stewart entitled Making Time#to_date public in Ruby 1.8.6. It was posted on 29 March 2007 at 2:02 pm.

You can find more posts by returning to the index.

Filed under: Notes
Tagged: , ,

I just got caught out by an upgrade to Ruby 1.8.6 and an app which I can’t as yet upgrade to Rails 1.2.3. Ruby 1.8.6 (and 1.9) make the Time#to_date and Time#to_datetime methods private so any code which depends on those methods being public will break.

The fix is very easy. I just copied the code from the relevant rails changeset and placed it in my environment.rb file:

class Time 
  %w(to_date to_datetime).each do |method| 
    public method if private_instance_methods.include?(method) 
  end 
end

Of course, the ideal is to upgrade to 1.2.3, but that’s not on the cards just yet for this particular project. In the meantime, having to add five lines isn’t too much trouble.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts

 

1 Comment

  • That’s an odd one. I’m curious to find out about the motivation behind the change (in Ruby).

    Comment by Sam Smoot — 29 March 2007 @ 9:05 pm

Sorry, the comment form is closed at this time.