Ruby Variable Scope

Welcome Folk,

Scope determines whether or not we have access to these variables from inside classes, methods, and other coded structures and we'll talk more about it once we introduce those structures, but it's kind of hard to show you examples when right now we only have our global scope to look at. So what we've been using so far are local variables, ones where we have nothing in front of it, and all you really need to know for now is that variable names can begin with the $ sign or the @ the front of it in order to give it different scopes. So, $ sign in front of it would give it global scope.
Variable Scope
Variable Scope 

Putting two @ signs in front of it makes it a class variable. Putting one @ sign in front of it, it becomes an instance variable and you'll be working with these later on. For now, just know that these are all legitimate ways that you can name your variable in Ruby.

Comments

Popular posts from this blog

How to solve migration issues with rails

ActiveRecords and ActiveRelation

CRUD Basics