I have "Date.today + 2.days" I need to format it using .strftime, but with the "+2.days" it doesn't recogni开发者_StackOverflow中文版ze that method.Any ideas?
Those nice helpers don't come with a vanilla ruby install. You need the activesupport
gem (part of Ruby on Rails).
$ gem install activesupport
$ irb
ruby-1.8.7-p249 > require 'rubygems'
=> true
ruby-1.8.7-p249 > require 'active_support'
=> true
ruby-1.8.7-p249 > Date.today
=> Fri, 16 Jul 2010
ruby-1.8.7-p249 > Date.today + 2.days
=> Sun, 18 Jul 2010
I don't see a problem, worked fine for me.
(Date.today + 2.days).strftime
#=> "2010-07-18"
精彩评论