Ruby Symbols/Keywords/Data Types Flashcards

(72 cards)

1
Q

alias

A

Creates an alias for an existing method, operator, or global variable.

Examples:

alias new old
alias :new :old
alias :new, :old

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

and

A

Logical operator; same as &&, except “and” has lower precedence.

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

BEGIN

A

Code, enclosed in { and }, that will run before the program runs.

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

begin

A

Begins a code block or group of statements; closes with “end” (not to be confused with BEGIN and END).

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

break

A

Terminates a “while” or “until” loop, or a method inside a block.

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

case

A

Compares an expression with one or more matching “when” clauses; closes with end. Can be used with or without a value to match against.

Example:
print "Enter a string: "
some_string = gets.chomp
case
when some_string.match(/\d/)
  puts 'String has numbers'
when some_string.match(/[a-zA-Z]/)
  puts 'String has letters'
else
  puts 'String has no numbers or letters'
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

class

A

Defines a class; closes with end.

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

def

A

Defines a method; closes with end.

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

defined?

A

Determines if a variable, method, super method, or block exists.

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

do

A

Begins a block and executes code in that block; closes with end.

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

else

A

Executes if previous conditional from “if”, “elsif”, “unless”, or “when”, is not true.

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

elsif

A

Executes if previous conditional from “if” or “elsif” is not true.

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

END

A

Code, enclosed in { and }, to run when the program ends.

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

end

A

Ends a code block (group of statements) starting with “begin”, “def”, “do”, “if”, etc.

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

ensure

A

Always executes at block termination; use after last rescue.

Example:
begin
# something which might raise an exception
rescue SomeExceptionClass => some_variable
# code that deals with some exception
else
# code that runs only if no exception was raised
ensure
# ensure that this code always runs, no matter what
end

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

false

A

Logical or Boolean false, instance of FalseClass.

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

for

A

Begins a for loop; used with in.

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

if

A

Executes code block if true. Closes with end.

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

module

A

Defines a module; closes with end.

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

next

A

Jumps before a loop’s conditional.

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

nil

A

Empty, uninitialized variable, or invalid, but not the same as zero; object of NilClass.

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

not

A

Logical operator; same as “!”

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

or

A

Logical operator; same as “||”, except “or” has lower precedence.

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

redo

A

Jumps after a loop’s conditional.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
rescue
Evaluates an expression after an exception is raised; used before ensure.
26
retry
Repeats a method call outside of rescue; jumps to top of block (begin) if inside rescue.
27
return
Returns a value from a method or block. May be omitted.
28
self
Current object (invoked by a method).
29
super
Calls method of the same name in the superclass. The superclass is the parent of this class.
30
then
A continuation for if, unless, and when. May be omitted.
31
true
Logical or Boolean true, instance of TrueClass.
32
undef
Makes a method in current class undefined.
33
unless
Executes code block if conditional statement is false.
34
until
Executes code block while conditional statement is false.
35
when
Starts a clause (one or more) under case.
36
while
Executes code while the conditional statement is true.
37
yield
Executes the block passed to the method.
38
\a
Bell or alert.
39
\b
Backspace.
40
\f
Formfeed.
41
\n
Newline.
42
\r
Carriage return.
43
\t
Tab.
44
\v
Vertical tab.
45
\\
Backslash
46
\'
Single quote
47
\"
Double quote
48
: :
Resolution operator. Used to resolve the scope of a constant/static symbol.
49
[ ]
Array
50
* *
Exponent
51
*
Multiplication
52
/
Division
53
%
Modulus; returns remainder
54
+
Addition
55
-
Subtraction
56
<<
Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.
57
>>
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.
58
&
Binary AND
59
|
Binary OR
60
>
Greater than
61
>=
Greater than or equal to
62
<
Less than
63
<=
Less than or equal to
64
Combined comparison operator. Returns 0 if first operand equals second, 1 if first operand is greater than the second and -1 if first operand is less than the second.
65
==
Is equal to
66
===
Used to test equality within a when clause of a case statement.
67
!=
Not equal to
68
=~
Match string to regular expression.
69
&&
Logical AND
70
| |
Logical OR
71
. .
Creates a range from start point to end point; inclusive.
72
. . .
Creates a range from start point to end point; exclusive.