Fundamentals Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Variables

A

Plain, lowercase words consisting of letters, digits, and underscores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Numbers

A

Integers may contain underscores. So 12_000 ( twelve thousand) is valid. Floats may be written in decimal or scientific notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

String literals

A

Created by both single and double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Symbols

A

words prefixed with a colon. Any valid variables is a valid symbol. They are like lightweight strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Constants

A

Constants are invariable variables - they are Capitalized, and once set, cannot be changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Method names

A

Generally appended via a dot ‘.’ to the end of a variable or constant. May contain bangs ‘!’ and question marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Method arguments

A

follow a method name and are both surrounded by parens and delimited by commas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Class Methods

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Global variables

A

Variables that begin with a $ are global.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Instance variables

A

Variables that begin with an @ sign are instance variables – usually used to define the attributes of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Class variables

A

Variables that begin with TWO at signs – @@ – are class variables. They attribute to all the instances of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Blocks

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Block arguments

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ranges

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Array

A

An array is a list of things delimited by commas and wrapped in square brackets. It is ordered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Hashes

A

A hash is a dictionary surrounded by curly braces. The items are delimited by commas, and the relation is expressed with an Ascii arrow. Ex:

{ ‘this’ => ‘stuff’, ‘that’ => ‘other stuff’ }

17
Q

Regular expressions

A

In Ruby, regular expressions are wrapped in forward slashes. So /ruby/ is a regex that matches ‘ruby’, and /^\d{3}-\d{3}-\d{4}/ matches a phone number (note the enclosing forward slashes).

18
Q

Nil

A

is a value, but it is the empty value. It is NOT undefined. To say that a variable is undefined is to say Ruby has no cognition of the variable - to say it is Nil is to say it is empty.

variable = Nil
Empty, but not undefined.

19
Q

if

A

Two forms: it either wraps its code body like braces (if is the opening brace, ‘end’ is the closing brace) OR, if the code body is a single statement, may just be appended to the end as in
print “some stuff here” if stuff

20
Q

unless

A

Unless is like a negative if. It’s code is only executed if the expression evaluates Nil or false

21
Q

==

A

The double equal, like in most languages, checks identity. But it is actually a method. a == b is allowed as a shorthand for a.==( b )

22
Q

«

A

’<

23
Q

elsif

A

Ruby uses ‘elsif’ to mean javascripts ‘else if’ or Python’s ‘elif’. Remember all Ruby control statement blocks are ended by ‘end’.

24
Q

How do I check if a value is Nil?

A

The method ‘.nil?’ appended to the value to be checked.