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