Reserved Words in Ruby Programming Language

Reserved Words in any programming language are keywords whose meaning have been defined internally in the language itself. These words are not allowed to be used by Programmers as variable names or function names. If in case you do use these as variable/function names then during execution some error will be thrown.

Below is a table listing all of Reserved Words in Ruby Programming Language with description for each one.

Reserved WordDescription
BEGINCode enclosed in { } to run before program runs
ENDCode enclosed in { } to run when program ends
aliasCreate alias for existing method, operator, global variable
andLogical AND Operator
beginBegins a block of code
breakTerminate a loop
caseComparing an expression with matching when clause which closes with end
classDefining a class
defDefining a function/method
defined?To check if some variable, function exists or not
doBegins a code block and execute code in the block, this ends with end keyword
elseExecutes following code if previous conditional is not true
elsifExecutes following code if previous conditional is not true
endFor ending a code block which started with keywords like begin, class, def, do, if
ensureAlways execute at block termination
falseLogical Boolean false value
forBegin a for loop
ifExecutes the code block in case conditional statement for if is true
inUsed with for loop
moduleDefining a module
nextJump to point immediately before evaluation of loop’s conditional
nilEmpty or invalid or always false
notLogical Negation Operator
orLogical Or Operator
redoJump after a loop conditional
rescueEvaluates the expression after an exception is raised
retry• When called outside of rescue repates the method call
• When called inside rescue jumps to top of block
returnReturns a value from a method or code block
selfCurrent Object
superCalls method of same name in the superclass
thenSeparator used with if, unless, when, case, rescue
trueLogical Boolean true
undefMakes a method/function undefined in current class
untilExecute code block while conditional statement is false
whenStarts a clause under case statement
whileExecutes the code block, until the conditional statement becomes false
yieldExecutes the code block which is passed to a method

These are Reserved Words in Ruby Programming Language, while writing code in Ruby Language just don’t use these words as variables or functions names.
I hope that this article provided you information about Reserved Words in Ruby Programming Language. I have put together many other articles about Python, JavaScript and other programming languages, you can check those articles here – Python Tutorials, JavaScript Tutorials.

Gagan

Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts