ruby on rails - Where is the Model.new method defined? -


i trying find source of models' new method. tried use source_location activerecord::base.new, , widget.new (where widget model), , do

find . -name *rb -exec grep -il "def new$" {} \; 

inside activerecord gem directory had no luck.

when ruby object instantiated via .new, runs object's initialize method. defined on class default:

1.9.3p327 :002 > activerecord::base.method(:new) => #<method: class#new> 

if want create custom initializer rails model, define initialize method. note there caveats this, because initialize isn't called activerecord. may better off adding after_initialize callback instead.

see how find method defined @ runtime? , in ruby, what's relationship between 'new' , 'initialize'? how return nil while initializing? more helpful information finding methods defined , how new , initialize related.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -