Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Class#allocate a public method in Ruby?

Tags:

object

ruby

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?

like image 663
Andrew Grimm Avatar asked May 05 '26 21:05

Andrew Grimm


1 Answers

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.

like image 97
Logan Capaldo Avatar answered May 09 '26 02:05

Logan Capaldo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!