开发者

Calling Methods in Ruby on Rails

开发者 https://www.devze.com 2023-03-25 21:23 出处:网络
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

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 i开发者_StackOverflow社区nitializer, 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消