Skip to content

Instantly share code, notes, and snippets.

@thaleshcv
Created October 30, 2018 17:43
Show Gist options
  • Save thaleshcv/5d2f128771c57bfa911de36514d8528b to your computer and use it in GitHub Desktop.
Save thaleshcv/5d2f128771c57bfa911de36514d8528b to your computer and use it in GitHub Desktop.
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