Ruby On Raisl 2.1新特性介绍

第11章:Ruby 1.9

By:IceskYsl At 2008.06.16

摘要:
本章简要介绍Rails2.1和Ruby1.9的关系,以及Rails2.1中增加的方法。

详细信息(DETAILS)

Rails的修改还集中体现在对Ruby1.9的支持,对新版Ruby中的细微改变都做了相应的调整以更好地适合要求,例如把 File.exists?修改为File.exist?
另外,在Ruby1.9中,去掉了Base64模块(base64.rb),因此,在Rails中,所有使用这个模板的都相应的修改为ActiveSupport::Base64

DATETIME 类的新方法(NEW METHODOS FOR DATETIME CLASS)

为了保证对Time类的兼容性(duck-typing),为DateTime 添加了三个新方法,分别为:#utc, #utc?#utc_offset,看个例子吧:
>> date = DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24))
#=> Mon, 21 Feb 2005 10:11:12 -0600
>> date.utc
#=> Mon, 21 Feb 2005 16:11:12 +0000
>> DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc?
#=> false
>> DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc?
#=> true
>> DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc_offset
#=> -21600