kill007
kill007

Reputation: 381

Calling Methods in Ruby on Rails

I am using Rails 2.3.2 and I am really miss something important in here.

I got some .rb files in my lib folder and in one of them, I got a line saying

User.new(x,y,z)

But when I go to the user.rb which is also sitting in lib folder, I don't find any method with defined with new. When I look at the initializer, it just assigns the incoming attributes to the variables like

def initialize(x,y,z)
  @x = x
  @y = y
  @z = z
end

Can you guys please tell me what I am really missing here. I know I am missing something really important.

Thanks

Upvotes: 2

Views: 202

Answers (1)

Mchl
Mchl

Reputation: 62359

In Ruby (not only Rails) calling ClassName.new() invokes initialize method from this class to ... well.. initialize the object created. The initialize method will be passed all the arguments that are passed to new()

See here for details: http://ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html

Upvotes: 1

Related Questions