Skip to content

Why do we return void for initializers? #2028

Answered by ParadoxV5
aaronmallen asked this question in Q&A
Discussion options

You must be logged in to vote

When you instantiate a class, you call the class method new (e.g., User.new).
Class#new is the one that returns instance.

The initializer we typically override is the instance method initialize, which is merely a callback Class#new triggers.
initializes seldom explicitly return self – think about all the def initialize blocks you’ve written.

#initialize is often overridden, but specifying a return type can be inconvenient for type checking.
#2008

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by aaronmallen
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants