Ex. 37 - Keyword Flashcards
BEGIN
Run this block when the script starts
BEGIN { puts “hi” }
END
Run this block when the script is done
END {puts “hi” }
alias
Create another name for a function.
alias X Y
and
Logical and, but lower priority than &&.
puts “Hello” and “Goodbye”
begin
Start a block, usually for exceptions.
begin end
break
Break out of a loop right now.
while true; break; end
case
Case style conditional, like an if.
case X; when Y; else; end
class
Define a new class.
class X; end
def
Define a new function.
def X( ); end
defined?
Is this class/function/etc. defined already?
defined? Class == “constant”
do
Create a block that maybe takes a parameter.
(0..5).each do |x| puts x end
else
Else conditional.
if X; else; end
elsif
Else if conditional
if X; elsif Y; else; end
end
Ends blocks, functions, classes, everything
begin end # many others
ensure
Run this code whether an exception happens or not.
begin ensure end