How instance method is called

Dear friends,

I came across this code snippet from my reading:

require 'active_record'

class Order < ActiveRecord::Base
end

order = Order.find(1)
...

Looking at: http://api.rubyonrails.org/ and search for find(), find() is
an instance public method. So why can we call Order.find(1) here?
Shouldn’t it be Order.new.find(1)?

it should Syntactic sugar,I dont know

201416գ1:41Warren Z. [email protected] д

Subject: how instance method is called
Date: lun 06 gen 14 06:41:33 +0100

Quoting Warren Z. ([email protected]):

Looking at: http://api.rubyonrails.org/ and search for find(), find() is
an instance public method. So why can we call Order.find(1) here?
Shouldn’t it be Order.new.find(1)?

This is an excellent question to pose to a rails-focused
audience. ‘find’ is obviously a class method, but maybe they use
special terminology in rails-land…

Carlo

Abinoam Jr. wrote in post #1132314:

Dear Warren,

IMHO, It probably “extended” (not “included”) that particular Module
that defines the #find method.

http://rubyquicktips.com/post/1133877859/include-vs-extend

Abinoam Jr.

Dear Abinoam,

I think this is the only explanation for this behavior. Thanks.

Dear Warren,

IMHO, It probably “extended” (not “included”) that particular Module
that defines the #find method.

http://rubyquicktips.com/post/1133877859/include-vs-extend

Abinoam Jr.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs