Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我创建了一个这样的 Data 对象。
semester_start_date = Date.new(2013,1,15)
现在我怎么能找到semester_start_date.day == 'Thursday'这件事的是否或任何其他日子?
semester_start_date.day == 'Thursday'
谢谢。
如果您使用的是 1.9,您应该可以这样做:
require 'date' d = Date.new(2013,1,15) d.thursday? #=> false d.wday #=> 2 Date::DAYNAMES[d.wday] #=> "Tuesday" d.tuesday? #=> true
我假设您实际上并不是在寻找与字符串“Thursday”相同的日期对象