Creating an initializer method in a Ruby class

One thing you may find handy in Ruby development is to create an initializer method. If you're wondering what is an initializer method, it is simply a method called initialize that will run every time when you create an instance of your class. In this method, you can give values to your variables, call other methods, and do just about anything that you think should happen when a new instance of that class is created.

If you're coming from other languages, this initializer method is similar to a constructor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.152.87