I have
class Fruit < ActiveRecord::Base
includes Skin
end
and the mixin module
module Skin
def initialize
self.skin = "fuzzy"
end
end
I want it so that
>> Fruit.new
#<Fruit skin: "fuzzy", created_at: nil, updated_at: nil>
Use the ActiveRecord
after_initialize
callback.
module Skin
def self.included(base)
base.after_initialize :skin_init
end
def skin_init
self.skin = ...
end
end
class Fruit < AR::Base
include Skin
...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With