These are notes I took while I was learning Ruby.
Comptuer studies ruby notes
Instance of a class is a sub-category of that class. E.g. greyhound; dog. Every object has a class. Objects are instances of classes. Methods define what an object can do and properties describe it. Constants start with a capital letter, sometimes they are all caps e.g. INTEREST = 0.012 #setting constant INTEREST to 1.2%
DOZEN = 12 #setting constant DOZEN to 12
Constants and variables store information in the memory for the duration of the use of the program. Like RAM? Constants can’t be changed but variables can be reassigned based on certain properties and data. Different types of classes:
Example of Object
6.5 or 3.9
2 or 3
Thisisastring or randomnumber34
Toronto [Dion Phaneuf]
Pittsburgh [Sidney Crosby]
Washington [Alex Ovechkin]
Haseeb [November 18]
Humza [August 6]
Hana [August 11]
Float = decimal number
Fixnum/Integer = whole number
String = letters and numbers
Array = an ordered list, a couple of objects put together in one list that can also be accessed independently Create a new array or reset an old one by using this:
array = Array.new
You can also show individual variables by doing:
you can also add objects to the array by:
subjects  = ‘Social Science’
Hash = Similar to array but not in order, each object does not have a number. It’s based on key and value pairs. Like if you put five names and assigned each a birthday. They would go based on those pairs. It assigns the first name to the second. E.g: friends = Hash.new
friends['Andrea'] = 'July 22'
friends['Mohammed'] = 'April 9'
Range = A sequence of values e.g. nums = 11..20
Fav_food = ‘pizza’ #setting variable fav_food to pizza
The quote marks around pizza identify that fav_food is a...
Please join StudyMode to read the full document