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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -