On Aug 21, 6:21 am, karthik k <cse.k.kart...@gmail.com> wrote:

> Below used in definition
>
> Model Employee
> --------------
> def self.list
>  find(:all)
> end
>
> In some case it is used inside
>
> Model Employee
> --------------
> def list
> self.find(:all)
> end
>
> So please let me know what is the reason behind this, using in two different
> way
>

self is the implicit receiver, ie calling self.find(:all) is the same
as calling find(:all). Sometimes it is useful to make it obvious what
you are doing

def self.list
...
end

creates a class method. The second example you gave probably wouldn't
run, unless the model had an instance method called find. More likely
is that you find something like that inside a

class << self
  def list
    ...
  end
end

in which case it is identical to the first example

Fred
> Guide me
>
> --
> Karthik.k
> Mobile - +91-9894991640
>
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to