Ruby Symbols/Keywords/Data Types Flashcards

You may prefer our related Brainscape-certified flashcards:
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
Q

rescue

A

Evaluates an expression after an exception is raised; used before ensure.

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

retry

A

Repeats a method call outside of rescue; jumps to top of block (begin) if inside rescue.

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

return

A

Returns a value from a method or block. May be omitted.

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

self

A

Current object (invoked by a method).

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

super

A

Calls method of the same name in the superclass. The superclass is the parent of this class.

30
Q

then

A

A continuation for if, unless, and when. May be omitted.

31
Q

true

A

Logical or Boolean true, instance of TrueClass.

32
Q

undef

A

Makes a method in current class undefined.

33
Q

unless

A

Executes code block if conditional statement is false.

34
Q

until

A

Executes code block while conditional statement is false.

35
Q

when

A

Starts a clause (one or more) under case.

36
Q

while

A

Executes code while the conditional statement is true.

37
Q

yield

A

Executes the block passed to the method.

38
Q

\a

A

Bell or alert.

39
Q

\b

A

Backspace.

40
Q

\f

A

Formfeed.

41
Q

\n

A

Newline.

42
Q

\r

A

Carriage return.

43
Q

\t

A

Tab.

44
Q

\v

A

Vertical tab.

45
Q

\

A

Backslash

46
Q

'

A

Single quote

47
Q

"

A

Double quote

48
Q

: :

A

Resolution operator. Used to resolve the scope of a constant/static symbol.

49
Q

[ ]

A

Array

50
Q
  • *
A

Exponent

51
Q

*

A

Multiplication

52
Q

/

A

Division

53
Q

%

A

Modulus; returns remainder

54
Q

+

A

Addition

55
Q

-

A

Subtraction

56
Q

«

A

Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.

57
Q

> >

A

Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.

58
Q

&

A

Binary AND

59
Q

|

A

Binary OR

60
Q

>

A

Greater than

61
Q

> =

A

Greater than or equal to

62
Q

<

A

Less than

63
Q

<=

A

Less than or equal to

64
Q
A

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
Q

==

A

Is equal to

66
Q

===

A

Used to test equality within a when clause of a case statement.

67
Q

!=

A

Not equal to

68
Q

=~

A

Match string to regular expression.

69
Q

&&

A

Logical AND

70
Q

|

A

Logical OR

71
Q

. .

A

Creates a range from start point to end point; inclusive.

72
Q

. . .

A

Creates a range from start point to end point; exclusive.