Fundamentals Flashcards
Variables
Plain, lowercase words consisting of letters, digits, and underscores.
Numbers
Integers may contain underscores. So 12_000 ( twelve thousand) is valid. Floats may be written in decimal or scientific notation.
String literals
Created by both single and double quotes.
Symbols
words prefixed with a colon. Any valid variables is a valid symbol. They are like lightweight strings.
Constants
Constants are invariable variables - they are Capitalized, and once set, cannot be changed.
Method names
Generally appended via a dot ‘.’ to the end of a variable or constant. May contain bangs ‘!’ and question marks.
Method arguments
follow a method name and are both surrounded by parens and delimited by commas.
Class Methods
are appended – usually – to variables and constants. If so, they are appended via double colons, like so:
Door::new (:oak)
I.e., make a new oak Door.
Global variables
Variables that begin with a $ are global.
Instance variables
Variables that begin with an @ sign are instance variables – usually used to define the attributes of an object.
Class variables
Variables that begin with TWO at signs – @@ – are class variables. They attribute to all the instances of the class.
Blocks
Blocks are delimited by left and right curly braces. { }
The braces may be replaced by the keywords ‘do’ and ‘end’ for the left and right respectively.
Block arguments
variables placed between pipe characters and delimited by commas are passed into the block. The block arguments are placed at the beginning (or top) of the block.
Ranges
A range is denoted by two values enclosed by parens and separated by a two or three dot ellipsis. Ex:
(1..10) is the range one through nine.
(‘a’..’z’) is the range consisting of the lowercase letters.
NOTE: if two dots are used, the final value is inclusive.
if three dots are used, the final value is excluded.
Array
An array is a list of things delimited by commas and wrapped in square brackets. It is ordered.