Keywords / Symbols Flashcards

(53 cards)

1
Q

BEGIN

A

Run this block when the script starts.

BEGIN { puts “hi” }

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

END

A

Run this block when the script is done.

END { puts “hi” }

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

alias

A

Create another name for a function.

alias X Y

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

and

A

Logical ‘and’, but lower priority than &&.

puts “Hello” and “Goodbye”

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

begin

A

Start a block, usually for exceptions.

begin end

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

break

A

Break out of a loop right now.

while true; break; end

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

case

A

Case style conditional, like an if.

case X; when y; else; end

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

class

A

Define a new class.

class x; end

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

def

A

Define a new function.

def X( ); end

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

defined?

A

Is the class/function/etc. defined already?

defined? Class == “constant”

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

do

A

Create a block that maybe takes a parameter.

(0..5).each do |x| puts x end

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

else

A

Else conditional

if X; else; end

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

elsif

A

Else conditional

if X; elsie Y; else; end

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

end

A

Ends blocks, functions, classes, everything

begin end # many others

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

ensure

A

Run this code whether an exception happens or not.

being ensure end

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

for

A

For loop syntax. the .each syntax is preferred.

for X in Y; end

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

if

A

if conditional.

if X; end

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

in

A

In part of for-loops.

for X in Y; end

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

module

A

Define a new module.

module X; end

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

next

A

Skip to the next element of a .each iterator.

(0..5).each {|y| next}

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

not

A

Logical ‘not’. But use ! instead.

not true == false

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

or

A

Logical ‘or’.

puts “Hello” or “Goodbye”

23
Q

redo

A

Rerun a code block exactly the same.

(0..5).each {|i| redo if i > 2}

24
Q

rescue

A

Run this code if an exception happens.

begin rescue X; end

25
retry
In rescue clause, says to try the block again. (0..5).each {|i| retry if i > 2}
26
return
Returns a value from a function. Mostly optional. return x
27
self
The current object, class, or module. defined? self == "self"
28
super
The parent class of this class. super
29
then
Can be used with if optionally. if true then puts "hi" end
30
undef
Remove a function definition from a class. undef X
31
unless
Inverse of if unless false then puts "not" end
32
until
Inverse of while, execute block as long as false. until false; end
33
when
Part of case conditionals. case X; when Y; else; end
34
while
While loop. while true; end
35
yield
Pause and transfer control to the code block. yield
36
nil
Represents "nothing" or "no value" x = nil
37
arrays
Stores a list of things. j = [1, 2, 3, 4, 5]
38
hashes
Stores a key=value mapping of things. e = {'x' => 1, 'y' => 2}
39
\\
Escape backslash
40
\'
Escape single-quote
41
\"
Escape double-quote
42
\a
Escape bell
43
\b
Escape backspace
44
\f
Escape form-feed
45
\n
Escape newline
46
\r
Escape carriage return
47
\t
Escape tab
48
\v
Escape vertical tab
49
..
Range inclusive (0..3).to_a == [0, 1, 2, 3]
50
...
Range exclusive (0...3).to_a == [0, 1, 2}
51
@
Object scope @var ; @@classvar
52
@@
Class scope @var ; @@classvar
53
$
Global scope $stdin