From: Hemant Kumar Date: 2007-01-11T13:30:31+09:00 Subject: Re: statement outside of any method in a class On Thu, 2007-01-11 at 13:01 +0900, Paul Smith wrote: > Newbie question: > > In the following code: > > class Person < ActiveRecord::Base > validates_presence_of :first_name > end > > validates_presence_of is a method call that is > specified outside of any method in class Person. > Hmm validates_presence_of method is not "outside any method" in class Person actually. Most probably (i.e taking into account rails meta magic), validates_presence_of is a class method, which is defined in class ActiveRecord::Base. So, when Person class inherits ActiveRecord::Base class it also inherits method validates_presence_of and above mentioned line invokes the method with argument :first_name. class Foobar def self.sayfoo arg puts "You said #{arg}" end end class Baz < Foobar sayfoo :rubyrocks end Output #=> "You said rubyrocks" Unlike C++, where you can have class or instance methods of a class(i.e static or normal methods of class) defined outside class definition, in Ruby its always inside class.