The keyword "self" in Ruby always refers to the current object within that context. Self can be referenced to a class as well as an instance ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_41_54 PM (2)](https://res.cloudinary.com/practicaldev/image/fetch/s--Cz79GIel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61tx0p0hckxs46s5s04r.png)
Scope refers to the level of accessibility our variables have. Allowing our program to have different levels of scope allow certain variables to be accessed or referenced at different times. 3 types of scope would be local, instance, and class
Local
Refers to a variable that is declared within a method and cannot be accessed outside of said method ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_17_50 PM (2)](https://res.cloudinary.com/practicaldev/image/fetch/s--L8cQI6gT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv6e84p3ltx2utkt4otx.png)
Class
Refers to variables that are accessed within all instances of our class. An easy way to detect a class variable is by the "@@" character next to our variable ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_20_57 PM (3)](https://res.cloudinary.com/practicaldev/image/fetch/s---Jx1cjtJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n755kjxzdpaqxrco8toj.png)
Instance
Instance variables values are only used within specific instances of an object. Similar to our class variable we use a single "@" in order to declare our instance variable ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_20_57 PM (4)](https://res.cloudinary.com/practicaldev/image/fetch/s--ixNu6Shr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckqv1lq0nvkq29ql2jz9.png)
Top comments (0)