created_at のメソッドを追加するモンキー パッチを作成しようとしています。
date_time_extras.rb ファイルを作成し、lib
次の内容でディレクトリに配置しました。
class DateTime
def beginning_of_hour
change(:min => 0)
end
end
私が行うコンソールから:
record.created_at.beginning_of_hour
しかし、これによりメソッドの欠落エラーが発生します。created_at は日時ではないようです。DateTime.new.beginning_of_hour
動作し、record.created_at.class
利回りが得られるためActiveSupport::TimeWithZone
です。
では、created_at 型の日付のモンキー パッチを作成するにはどうすればよいでしょうか。
Rails バージョン 3.0.10 を使用しています。
アップデート
また試した
module ActiveSupport
class TimeWithZone
def beginning_of_hour
change(:min => 0)
end
end
end
無駄に