Keywords / Symbols 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 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
Q

retry

A

In 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

unless

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

36
Q

nil

A

Represents “nothing” or “no value”

x = nil

37
Q

arrays

A

Stores a list of things.

j = [1, 2, 3, 4, 5]

38
Q

hashes

A

Stores a key=value mapping of things.

e = {‘x’ => 1, ‘y’ => 2}

39
Q

\

A

Escape backslash

40
Q

'

A

Escape single-quote

41
Q

"

A

Escape double-quote

42
Q

\a

A

Escape bell

43
Q

\b

A

Escape backspace

44
Q

\f

A

Escape form-feed

45
Q

\n

A

Escape newline

46
Q

\r

A

Escape carriage return

47
Q

\t

A

Escape tab

48
Q

\v

A

Escape vertical tab

49
Q

..

A

Range inclusive

(0..3).to_a == [0, 1, 2, 3]

50
Q

A

Range exclusive

(0…3).to_a == [0, 1, 2}

51
Q

@

A

Object scope

@var ; @@classvar

52
Q

@@

A

Class scope

@var ; @@classvar

53
Q

$

A

Global scope

$stdin