Keyword Examples Flashcards

Name the keyword from the given example

You may prefer our related Brainscape-certified flashcards:
1
Q

BEGIN { puts “hi” }

A

BEGIN: Run this block when the script starts

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

END { puts “hi” }

A

END: Run this block when the script is done

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

alias X Y

A

alias: create another name for a function

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

puts “Hello” and “Goodbye”

A

and: Logical and, but lower priority than &&

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

begin end

A

begin: Start a block, usually for exceptions

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

while true; break; end

A

break: break out of a loop right now

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

case X; when Y; else; end

A

case: Case style conditional, like an if

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

class x; end

A

class: Define a new class

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

def X(); end

A

def: define a new function

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

defined? Class == “constant”

A

defined?: Is this class/function/etc. defined already?

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

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

A

do: Create a block that maybe takes a parameter

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

if X; else; end

A

else: Else conditional

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

if X; elsif Y; else; end

A

elsif: Else if conditional

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

begin end # many others

A

end: Ends blocks, functions, classes, everything

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

begin ensure end

A

ensure: 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 X in Y; end

A

for: For loop syntax. The .each syntax is preferred

17
Q

if X; end

A

if: If conditional

18
Q

for X in Y; end

A

in: In part of for-loops

19
Q

module X; end

A

module: Define a new module

20
Q

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

A

next: skip to the next element of a .each iterator

21
Q

not true == false

A

not: logical not. But use ! instead

22
Q

puts “Hello” or “Goodbye”

A

or: Logical or.

23
Q

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

A

redo: Rerun a code block exactly the same

24
Q

begin rescue X; end

A

rescue: Run this code if an exception happens

25
Q

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

A

retry: In a rescue clause, says to try the block again

26
Q

return X

A

return: Returns a value from a function

27
Q

defined? self == “self”

A

self: The current object, class, module

28
Q

super

A

super: The parent of this class

29
Q

if true then puts “hi” end

A

then: Can be used with if optionally

30
Q

undef X

A

undef: Remove a function definition from a class

31
Q

unless false then puts “not” end

A

unless: Inverse of if

32
Q

until false; end

A

until: Inverse of while, execute block as long as false

33
Q

case X; when Y; else; end

A

when: Part of case conditionals

34
Q

while true; end

A

while: while loop

35
Q

yield

A

yield: Pause and transfer control to the code block