Comptuer Studies Ruby Notes

Only available on StudyMode
  • Download(s) : 172
  • Published : March 25, 2013
Open Document
Text Preview
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:

ClassExample of Object
Float6.5 or 3.9
Fixnum2 or 3
StringThisisastring or randomnumber34
ArrayMonday
Tuesday
Wednesday
Thursday
Friday
Or
January
February
March
April
HashToronto [Dion Phaneuf]
Pittsburgh [Sidney Crosby]
Washington [Alex Ovechkin]
Or
Haseeb [November 18]
Humza [August 6]
Hana [August 11]
Range11..20
Or
Hi..Ho

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:
array[number] e.g.
subjects[3]
you can also add objects to the array by:
subjects [4] = ‘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
Setting variable:
Fav_food = ‘pizza’ #setting variable fav_food to pizza
The quote marks around pizza identify that fav_food is a...
tracking img