Created
October 30, 2018 17:43
-
-
Save thaleshcv/5d2f128771c57bfa911de36514d8528b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyObj | |
include ActiveModel::Model | |
include ActiveRecord::AttributeAssignment | |
attr_accessor :my_date | |
def initialize(*params) | |
assign_attributes(*params) | |
end | |
# AttributeAssignment needs to know the class | |
def type_for_attribute(name) | |
case name | |
when 'my_date' | |
klass = Date | |
end | |
OpenStruct.new(klass: klass) | |
end | |
end | |
obj = MyObj.new('my_date(1i)' => '2015', 'my_date(2i)' => '1', 'my_date(3i)' => '31') | |
obj.my_date # Sat, 31 Jan 2015 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment