Ruby Keywords 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 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 block, functions, classes, everything.
ensure
Run this code whether an exception happens or not.