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 Word | Description |
---|---|
BEGIN | Code enclosed in { } to run before program runs |
END | Code enclosed in { } to run when program ends |
alias | Create alias for existing method, operator, global variable |
and | Logical AND Operator |
begin | Begins a block of code |
break | Terminate a loop |
case | Comparing an expression with matching when clause which closes with end |
class | Defining a class |
def | Defining a function/method |
defined? | To check if some variable, function exists or not |
do | Begins a code block and execute code in the block, this ends with end keyword |
else | Executes following code if previous conditional is not true |
elsif | Executes following code if previous conditional is not true |
end | For ending a code block which started with keywords like begin, class, def, do, if |
ensure | Always execute at block termination |
false | Logical Boolean false value |
for | Begin a for loop |
if | Executes the code block in case conditional statement for if is true |
in | Used with for loop |
module | Defining a module |
next | Jump to point immediately before evaluation of loop’s conditional |
nil | Empty or invalid or always false |
not | Logical Negation Operator |
or | Logical Or Operator |
redo | Jump after a loop conditional |
rescue | Evaluates 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 |
return | Returns a value from a method or code block |
self | Current Object |
super | Calls method of same name in the superclass |
then | Separator used with if, unless, when, case, rescue |
true | Logical Boolean true |
undef | Makes a method/function undefined in current class |
until | Execute code block while conditional statement is false |
when | Starts a clause under case statement |
while | Executes the code block, until the conditional statement becomes false |
yield | Executes 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.
No Comments
Leave a comment Cancel