ActiveRecord::Base#becomes with initialize value

30 views
Skip to first unread message

신재현

unread,
May 9, 2016, 11:13:17 PM5/9/16
to Ruby on Rails: Core
I propose that initialize values in `becomes` method

for example,

class Book < ApplicationRecord
end


class PaperBook < Book
  after_initialize
do |boo|
    material
||= "paper"
 
end
end


> book = Book.new
> book.material
# => nil


> book.becomes!(PaperBook).materal
# => "paper"

Shoul I implement the feature?
Does it make sense?

Roque Pinel

unread,
May 9, 2016, 11:20:03 PM5/9/16
to rubyonra...@googlegroups.com
If the callback belonged to `Book`, would you re-run it with `becomes`? Sounds confusing.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

신재현

unread,
May 9, 2016, 11:59:49 PM5/9/16
to Ruby on Rails: Core
Nope, If attribute has value, it is not initialized.
Reply all
Reply to author
Forward
0 new messages