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)?

···

--
Posted via http://www.ruby-forum.com/.

Quoting Warren Zhang (lists@ruby-forum.com):

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)?

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

···

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

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

it should Syntactic sugar,I don’t know

在 2014年1月6日,下午1:41,Warren Zhang <lists@ruby-forum.com> 写道:

···

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)?

--
Posted via http://www.ruby-forum.com/\.

Dear Warren,

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

Abinoam Jr.

···

On Mon, Jan 6, 2014 at 4:25 AM, Carlo E. Prelz <fluido@fluido.as> wrote:

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

Quoting Warren Zhang (lists@ruby-forum.com):

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)?

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

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

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.

···

--
Posted via http://www.ruby-forum.com/\.