# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# birth_date :date not null
class User < ApplicationRecord
end
# Valid Date
# type casted
# be Date
User.new(birth_date: "19800229").birth_date
# => Fri, 29 Feb 1980
# valid Date
# before Type Casted
# be String
User.new(birth_date: "19800229").birth_date_before_type_cast
# => "19800229"
# Invalid Date
# type casted
# be nil
User.new(birth_date: "19800230").birth_date
# Invalid Date
# Get not type casted input
User.new(birth_date: "19800230").birth_date_before_type_cast
# => "19800230"
Other methods
User.new.methods.grep /birth_date/
=> [:birth_date=,
:birth_date,
:birth_date?,
:birth_date_changed?,
:birth_date_change,
:birth_date_will_change!,
:birth_date_was,
:birth_date_previously_changed?,
:birth_date_previous_change,
:restore_birth_date!,
:saved_change_to_birth_date?,
:birth_date_before_last_save,
:saved_change_to_birth_date,
:birth_date_change_to_be_saved,
:will_save_change_to_birth_date?,
:birth_date_in_database,
:birth_date_before_type_cast]
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。