在控制台上工作时,Date.today -12.months
和Date.today - 12.months
给出了不同的输出,有人可以解释Ruby如何解析这两个语句吗?了解Ruby如何解析语句
作为精简,Date.today -12.months
的输出是当前日期,而Date.today - 12.months
返回一个一年前的时间戳,这是我在第一种情况下预期的结果。
Date.today ((- 12).months)
Date.today - 12.months
被解析为:
Ruby没有方法'Fixnum#months'(或'Integer#months')。你需要一个Rails的标签。 –
提示:使用'-w'启用警告(与irb和ruby一起使用)。 – cremno