+ 1

Can we have multiple initializers for a class

Can we have multiple initializer method for a class. Like over loaded constructors in c++

17th Jul 2017, 11:31 AM
Avinash Gupta
Avinash Gupta - avatar
2 odpowiedzi
+ 1
Sadly not, because Ruby doesn't know beforehand which types the arguments gonna have. You can however create a initializer with the splat operator: https://code.sololearn.com/cDQ6rKdYeO13/#rb Or you can give the initializer default arguments: https://code.sololearn.com/c2zRI2vl8U2J/#rb
17th Jul 2017, 8:40 PM
Jacques Müller
Jacques Müller - avatar
0
Thanks alot Jacques.
18th Jul 2017, 6:47 PM
Avinash Gupta
Avinash Gupta - avatar