Why is MyClass.allocate a public method in Ruby? Under what circumstances would you want to create an object but not run initialize on it?
Why is MyClass.allocate a public method in Ruby? Under what circumstances would you want
Share
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.
Deserialization comes to mind. A class may be serializable but might not have an initialize that takes no arguments, and that code shouldn’t need to initialize it to something just to immediately undo that work.
Basically any scenario where you initialize an object differently then your typical case it becomes useful to separate those two steps.