0

When instantiating an object in Ruby, one mostly uses what appears to be the method #new.

o = Object.new

But there usually is no 'new' method. Instead what happens (and correct me please if I am wrong), is that a method called #initialize is executed to create the new object.

Why did the Ruby creators decide to introduce this distinction between defining and calling this method?

Edit: While the alleged duplicate question asks (besides another, more concrete question) for the relation between those two methods, I want to know WHY the relationship was chosen.

Flip
  • 6,233
  • 7
  • 46
  • 75
  • `.new` is the class method that creates a instance, `#initialize` is the instance method called by the newly created instance by design. Using different names clarifies that difference. – SteveTurczyn Mar 20 '17 at 12:08
  • @Andrey Deineko I don't know why did you block this question, this question has nothing to do with your shown question. Read his edit he is making more clearer. – RAJ Mar 20 '17 at 12:18
  • @RAJ thank you, I also don't get it. – Flip Mar 20 '17 at 12:22
  • After having this one answered there might appear new question with title *What are the reasons behind having initialize method called with new -* would you advocate it will *`have nothing to do with this question`* as well? – Andrey Deineko Mar 20 '17 at 12:31
  • Would you, on the other hand, agree, that `having-something-to-do-with` is slightly different than `being-a-exact-duplicate-of`? – Flip Mar 20 '17 at 12:40
  • Even if this question is not a duplicate, it is still off-topic: "Why did the Ruby creators decide to introduce this distinction between defining and calling this method?" is a question that can only be answered by matz, and matz doesn't have a [so] account, as far as I know. See also [*Why we're not customer support for \[your favorite company\]*](https://meta.stackoverflow.com/q/255745/2988) for a slightly related discussion. – Jörg W Mittag Mar 20 '17 at 12:40
  • I disagree. While Matz might be the only one to provide the final argument, there still might be some technical motivation behind his decision. This is what I wanted to know. – Flip Mar 20 '17 at 12:45
  • @Flip I would agree that it's not exact duplicate, but it is close enough IMO. Also, as Jörg says, it would otherwise be closed as off-topic... – Andrey Deineko Mar 20 '17 at 12:55
  • @AndreyDeineko If you don't want to answer, you could stay away because I find this question is very reasonable. Don't block the question unnecessary like this because people will loss the freedom of asking the question. Kindly do this favor. @ Jörg W Mittag you need not to decide whether Matz only can answer or some other people can answer as well. He has that question so he has asked, I find this question is very meaningful and large deviation from the question which has showed as answered. – RAJ Mar 20 '17 at 13:19
  • @RAJ Matz written Ruby. Only he (and the holy Universe) knows answer to question "Why?". Since Matz does not have account on SO and I doubt Universe does - no one will ever be capable of answering that. – Andrey Deineko Mar 20 '17 at 13:23
  • @AndreyDeineko That's not what you concluded, don't jump into the conclusion of Jörg W Mittag. You said since it's slightly deviated from original question it can't be asked. I am saying that if you are not interested, you could stay away from that question, let others who are interested can answer the question, if they don't know they would eliminate that. What's your problem? Are you trying to save the pages of Stackoverflow? huh? I find this question is highly deviated from the one by you have shown. – RAJ Mar 20 '17 at 13:26
  • Maybe you can ask this on the [Computer Science Stack Exchange](http://cs.stackexchange.com/questions/tagged/language-design) site with the tag `language-design`? If you do please post the link here in the comments. – Sagar Pandya Mar 20 '17 at 18:38

0 Answers0