Keywords Flashcards
Keywords in Ruby and what they do
BEGIN
Run this block when the script starts
END
Run this block when the script is done
alias
create another name for a function
and
Logical and, but lower priority than &&
begin
Start a block, usually for exceptions
break
break out of a loop right now
case
Case style conditional, like an if
class
Define a new class
def
define a new function
defined?
Is this class/function/etc. defined already?
do
Create a block that maybe takes a parameter
else
Else conditional
elsif
Else if conditional
end
Ends blocks, functions, classes, everything
ensure
Run this code whether an exception happens or not
ensure
Run this code whether an exception happens or not
for
For loop syntax. The .each syntax is preferred
if
If conditional
in
In part of for-loops
module
Define a new module
next
skip to the next element of a .each iterator
not
logical not. But use ! instead
or
Logical or.
redo
Rerun a code block exactly the same
rescue
Run this code if an exception happens
retry
In a rescue clause, says to try the block again
return
Returns a value from a function
self
The current object, class, module
super
The parent of this class
then
Can be used with if optionally
undef
Remove a function definition from a class
unless
Inverse of if
until
Inverse of while, execute block as long as false
when
Part of case conditionals
while
while loop
yield
Pause and transfer control to the code block