Object Initialization
Objects are created using the
new
method of each object’s class. After a
new
object is created by the
new
method, the object’s
initialize
method is called with the arguments of
the new
method passed to it. Blocks associated
with the new
method are also passed directly to
initialize
. For consistency, you should initialize
objects by redefining the initialize
method,
rather than the new
method. The visibility of
methods named initialize
is automatically made
private.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.