⏎ Return

Ruby Classes

What is a Ruby class? Well a class is the blueprint from which individual objects are created.Within the class you can define many different methods that will make up that indvidual class. For example, if my class is Person. I can define methods like name, age, occupation... these things make up the class Person. What is an instance variable and when is it used? An instance variable is a variabled defined in a class, for which each instanitated object of the class has a separate copy. Basically, once you call an instance variable within the class you can continue to use it throughout the class in different methods without renaming that variable.

In the photo above, you will see that we called a class Person. An then you see an attr_accessor fname and lname, what this attr_accessor is doing is saying that fname and lname can be changed throughout the class without renaming the variable, basically without having to do this: fname = new_name, everytime. We then see def initalize(fname, lname) then we see @fname = fname ... this is where we are calling the instance variable fname. Below that you see @lname = lname... this is where we called the instance variable lname. So the @ symbol is how we use to call the instance variable. Easy right?