Ruby Self and its role
Hi, This is Shubham Mishra from India, this is the part of Ruby on Rails exploration journey. In this post we will discuss about the ruby's self keyword and its usage. You may have come up with self while working on the existing code base, but not got the significance of it, then read this post to understand it in a simpler manner. Even if you are not a ruby developer then also this article will be helpful since self is used in almost many programming languages. Wait ruby's self is like above image only, it is representing the current object in the current context. Confused? 🤪, wait let me tell you with the example, Now lets decode above code to understand what is the self is, Firstly, we have a class Student with a constructor to initialise the instance variable score , and a method named : show_info , Then we have created a instance of Student class, and stored the object into variable s1, Now lets decode specifically the :show_inf...