Variables&Methods

Posted by kcluniesa on January 18, 2019

Variables are words or characters that hold values. A variable can point to different types of values including numbers, strings, arrays, and hashes. Variables allow us to store information and hold that information so we can retrieve it later. A variable is the location where information resides and when we need it we know where to find it.

Methods are used to bundle one or more repeatable statements into a single unit. Instead of writing a piece of code over and over, methods allows us to extract common code to one place. Methods define a new thing that our program can do.

If variables are used to teach our program about data, then methods can be thought of as teaching our program about a new behavior it can use. Variables are like nouns, methods are like verbs. Variables encapsulate and abstract data, methods encapsulate and abstract a procedure.