In Ruby, such code is legal:
class Aclass
m = 1
end
but semantically speaking, what will m be, and how is it supposed to be accessed?
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.
mis just a local variable. It can only be accessed from within the class definition. It could be used to bootstrap the class for instance, but it can’t be accessed from anywhere else.For example:
That code would be run only once, when you require the file containing that class. This is somewhat analogous to Java’s static initialisation blocks.