0

When we create a new instance of a class, we do the following:

Given the class:

class Person
  def initialize
  end
end

person = Person.new

I believe that since class Person is an instance of Class, the new method is defined there. However, how is the initialize method called?

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
  • @rsenna it's not a direct dup. – Luiggi Mendoza Sep 05 '14 at 14:57
  • Hey there Hommer Smith, It seems that the answer to your question is really that calling Person.new *is* what calls the initialize method. With the case of the initialize method it is that the Ruby language simply expects and seeks out a method named initialize which it then runs any time the you create a new instance of a class. Here's the first write up I found: http://www.rubyist.net/~slagell/ruby/objinitialization.html – campo Sep 05 '14 at 15:02

0 Answers0