Ex. 37 - Keyword Flashcards

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

begin 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

17
Q

if

A

If conditional.

if X; end

18
Q

in

A

In part of 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.

(o..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 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
Q

retry

A

In a rescue clause, says to try the block again.

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

26
Q

return

A

Returns a value from a function. Mostly optional.

return X

27
Q

self

A

The current object, class, or module.

defined? self == “self”

28
Q

super

A

The parent class of this class.

super

29
Q

then

A

Can be used with if optionally.

if true then puts “hi” end

30
Q

undef

A

Remove a function definition from a class.

undef X

31
Q

unles

A

Inverse of if.

unless false then puts “not” end

32
Q

until

A

Inverse of while, execute block as long as false.

until false; end

33
Q

when

A

Part of case conditionals.

Case X; when Y; else; end

34
Q

while

A

While loop.

while true; end

35
Q

yield

A

Pause and transfer control to the code block.

yield