Ruby Keywords Flashcards Preview

Ruby Keywords > Ruby Keywords > Flashcards

Flashcards in Ruby Keywords Deck (35):
1

BEGIN

run this block when the script starts. BEGIN { puts "hi" }

2

END

Run this block when the script is done. END { puts "hi" }

3

alias

Create another name for a function. alias x y

4

and

Logical and, but lower priority than &&. puts "hello" and "goodbye"

5

begin

Start a block, usually for exceptions. begin end

6

break

Break out of a loop right now. while true; break; end

7

case

Case conditional, like an if. case X; when Y; else; end

8

class

Define a new class. Class X; end

9

def

Define a new function. def X(); end

10

defined?

Is this class/function/etc. defined already? defined? Class == "constant"

11

do

Create a block that maybe takes a parameter. (0..5).each do |x| puts x end

12

else

Else conditional If X; else; end

13

elsif

Else if conditional if X; elsif Y; else; end

14

end

Ends block, functions, classes, everything.

15

ensure

Run this code whether an exception happens or not.

16

for

For loop syntax. The .each syntax is preferred in ruby. for X in Y; end

17

if

If conditional. if X; end

18

in

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

19

module

Define a new module. module X; end

20

next

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

21

not

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

22

or

Logical or. puts "hello" or "goodbye"

23

redo

rerun a code block exactly the sames
(0..5).each {|e| redo if e > 2 }

24

rescue


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