Ruby Keywords Flashcards

(35 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 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 this 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 if conditional if X; elsif Y; else; end

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

end

A

Ends block, functions, classes, everything.

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.

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 in ruby. for X in Y; end

17
Q

if

A

If conditional. if X; end

18
Q

in

A

In part for-loops. for X in Y; end

19
Q

module

A

Define a new module. module X; end

20
Q

next

A

Skip to the next element of a .each iterator. (0..5).each { |y| next }

21
Q

not

A

Logical not. But use ! instead. not true == false

22
Q

or

A

Logical or. puts “hello” or “goodbye”

23
Q

redo

A

rerun a code block exactly the sames

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

24
Q

rescue

A

Run this code if an exception happens

begin rescue X; end

25
retry
In a rescue clause, says to try the block again. | (0..5).each { |e| retry if e < 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 of this class
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 conditional | case X; when Y; else; end
34
while
While loop | while true; end
35
yield
Pause and transfer control to the code block