Comptuer Studies Ruby Notes Essay

835 Words Mar 12th, 2013 4 Pages
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:
Class Example of Object
Float 6.5 or 3.9
Fixnum 2 or 3
…show more content…
Some are only used for a small task while others may be used for larger tasks and appear several times within the program. Constants’ scope depends on how often it is declared. If a constant is only declared within a class or module it’s scope is within that scope or module. However if it is declared outside of that class or module it’s scope is wider or “global”.
There four different variable scopes.
Local variables are confined to the part of the program in which they are declared. If the variable is only declared within a method it is restricted to when that method is used or executed. It can’t be used anywhere else in the program. (e.g. fav_food)
Global variables can be declared anywhere in the program and are accessible from anywhere in the program. They are identified by a preceding “$” e.g. $fav_food. Global variables, however have to be used with extreme caution due to the fact that their values can be changed anytime in the program, sometimes by accidental or careless coding, these accidents can cause huge problems and are not easily fixable.
Class variables are confined to a specific class but once all instances of the class are created the value of the variable is shared

Related Documents