O'Reilly logo

Learning Ruby by Michael Fitzgerald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ruby's Reserved Words

Table A-1 lists all of Ruby's reserved words.

Table A-1. Ruby's reserved words

Reserved word

Description

BEGIN

Code, enclosed in { and }, to run before the program runs.

END

Code, enclosed in { and }, to run when the program ends.

alias

Creates an alias for an existing method, operator, or global variable.

and

Logical operator; same as && except and has lower precedence. Compare with or.

begin

Begins a code block or group of statements; closes with end.

break

Terminates a while or until loop or a method inside a block.

case

Compares an expression with a matching when clause; closes with end. See when.

class

Defines a class; closes with end.

def

Defines a method; closes with end.

defined?

A special operator that determines if a variable, method, super method, or block exists.

do

Begins a block and executes code in that block; closes with end.

else

Executes following code if previous conditional, in if, elsif, unless, or when, is not true.

elsif

Executes following code if previous conditional, in if or elsif, is not true.

end

Ends a code block (group of statements) started with begin, def, do, if, etc.

ensure

Always executes at block termination; use after last rescue.

false

Logical or Boolean false; instance of FalseClass. See true.

for

Begins a for loop; used with in.

if

Executes code block if conditional statement is true; closes with end. Compare with unless, until.

in

Used with for loop. See for.

module

Defines a module; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required