If I run this file as “ruby x.rb“:
class X
end
x = X.new
What is the thing that is calling “X.new“?
Is it an object/process/etc?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Everything in Ruby occurs in the context of some object. The object at the top level is called “main”. It’s basically an instance of Object with the special property that any methods defined there are added as instance methods of Object (so they’re available everywhere).
So we can make a script consisting entirely of:
and it will print “105640” and “Look, I have instance variables!”.
It’s not something you generally need to concern yourself with, but it is there.