Ruby is one of the leading programming languages in the world. It is the open source programming language which is easily modified, distributed and copied. The programming using this language is difficult if you don’t know the proper syntax of the language so according to the language structure you must recall a fair share of syntax, commands, and functions. Ruby is the pure object-oriented and flexible programming language because it allows a user to alter parts freely. Hire freelancers who have knowledge and experience in Ruby programming language.
Ruby Console Basics:
The console is the effective way of interacting with the computer. The console is also known as command line, command prompt, and terminal. Through this console, you can do anything with your graphical desktop user interface. Following are some list of the commands.
Cd- Change directory to the specified directory on the console.
Ls- List all content of a directory.
pwd- Shows the current directory
mkdir- Create a new directory
rm- Delete the directory.
Variables in Ruby:
Variables are the memory location which holds the data used in a program. There are five types of variables in Ruby programming language.
- Global Variables: Global Variables begins with the $.
- Instance Variables: Instance variables begins with @
- Class variables: Class variables begin with the @@
- Local Variables: Local variables begins with lower case letter
- Constant: Constant variables begin with upper case letter.
Operators in Ruby:
Ruby programming language has an extensive set of operators. Following are some types of operators.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Parallel Assignment Operators
- Bitwise Operators
- Logical Operators
- Ternary Operators
- Range Operators
Conditional Statements in Ruby:
Conditional statements enable your program to make correct decisions and perform right actions. Following are the list of the conditional operators.
- if else statement
if conditional [then]
[elsif conditional [then]
- Unless Statement
unless conditional [then]
- Case Statements
[when expression [, expression …] [then]
- While Statements
while conditional [do]
- Until Statements
until conditional [do]
- For Statement
for variable [, variable …] in expression [do]
A regular expression is a sequence of characters which allows you to match or find other strings or set of strings using a specialized syntax held in pattern between slashes or between arbitrary delimiters followed by %r. Hire freelancers who have knowledge and experience in Ruby programming language.
/pattern/im # option can be specified
%r!/usr/local! # general delimited regular expression
Strings in Ruby:
The Ruby holds string objects and manipulates an arbitrary sequence of one or more bytes typically representing characters which represent human language. The simplest string literals get enclosed in single quotes, and the text within the single quotes is a string.
‘This is a simple Ruby string literal.’
Array in Ruby:
The array is the collection of a similar type of objects and its stores the fixed sized sequential elements. The arrays of Ruby have an ordered way; integer-indexed collections of any object and each element in an array are associated with and referred to by an index. The array holds an object such as String, Integer, Fixnum, Hash, and other array objects. You can find multiple freelance services to work on Ruby
There are many ways to create or initialize an array. Following are the syntax of the creation of the array.
Names = Array.new
Exception Handling in Ruby:
The exception and execution always happen together. If you are trying to open a file which does not exist and if you do not handle this situation properly, then your program fails to run.
If any exception occurs, the program stops working. The exception is the process of handling different errors that occur during a program execution and performs a perfect action instead of stopping the program execution. The programming language Ruby has an excellent mechanism for handling exceptions. Following are the syntax of exception.
# Other exceptions
# Always will be executed
More than one thread of execution is known as multithreading. In each thread, statements execute sequentially, but different threads get executed parallelly. Ruby allows the programmer to write multithreaded programs with the thread class. The thread concept in Ruby is lightweight and achieves efficiency in concurrency of code.
# Thread #1 is running here
# Thread #2 runs this code
# Thread #1 runs this code
This article is about the Ruby programming cheat sheet. This cheat sheet covers all the important syntax of the Ruby language, and it is most useful when you are performing the programming in Ruby programming language.
- Top PHP interview questions and answers 2020 - July 7, 2020
- How to create a Whatsapp account using the Australian number? - June 28, 2020
- Top C++ interview questions And answers 2020 - June 19, 2020