Author: admin
-
Ruby while Loop
The Ruby while loop is used to iterate a program several times. If the number of iterations is not fixed for a program, while loop is used. Ruby while loop executes a condition while a condition is true. Once the condition becomes false, while loop stops its execution. Syntax: Example: Output: Ruby do while Loop…
-
Ruby for Loop
Ruby for loop iterates over a specific range of numbers. Hence, for loop is used if a program has fixed number of iterations. Ruby for loop will execute once for each element in expression. Syntax: Ruby for loop using range Example: Output: Ruby for loop using array Example: Output:
-
Ruby Case Statement
In Ruby, we use ‘case’ instead of ‘switch’ and ‘when’ instead of ‘case’. The case statement matches one statement with multiple conditions just like a switch statement in other languages. Syntax: Example: Output: Look at the above output, conditions are case sensitive. Hence, the output for ‘Saturday’ and ‘saturday’ are different.
-
Ruby If-else Statement
The Ruby if else statement is used to test condition. There are various types of if statement in Ruby. Ruby if statement Ruby if statement tests the condition. The if block statement is executed if condition is true. Syntax: Example: Output: Ruby if else Ruby if else statement tests the condition. The if block statement…
-
Ruby Data types
Data types represents a type of data such as text, string, numbers, etc. There are different data types in Ruby: Numbers Integers and floating point numbers come in the category of numbers. Integers are held internally in binary form. Integer numbers are numbers without a fraction. According to their size, there are two types of…
-
Ruby Variables
Ruby variables are locations which hold data to be used in the programs. Each variable has a different name. These variable names are based on some naming conventions. Unlike other programming languages, there is no need to declare a variable in Ruby. A prefix is needed to indicate it. There are four types of variables…
-
Ruby Operators
Ruby has a built-in modern set of operators. Operators are a symbol which is used to perform different operations. For example, +, -, /, *, etc. Types of operators: Unary Operator Unary operators expect a single operand to run on. Operator Description ! Boolean NOT ~ Bitwise complement + Unary plus Example In file hello.rb,…
-
Hello Ruby Program
Now we will write a simple program of Ruby. Before writing Hello World program, we are assuming that you have successfully installed Ruby in your system. Requirement for Hello Ruby Program Creating Hello Ruby Program 1) Use any text editor and create a hello.rb file. Write the following code, 2) Connect Ruby path to the…
-
Ruby vs Python
Similarities Differences Terms Ruby Python Definition Ruby is an open source web application programming language. Python is a high level programming language. Object Oriented Fully object oriented programming language. Not fully object oriented programming language. Developer Yukihiro Matsumoto in 1990s. Guido Van Rossum in 1980s. Developing Environment EclipseIDE is supported. multiple IDEs are supported. Libraries…
-
What is Ruby
Ruby is a dynamic, open source, object oriented and reflective programming language. Ruby is considered similar to Perl and Smalltalk programming languages. It runs on all types of platforms like Windows, Mac OS and all versions of UNIX. It is fully object oriented programming language. Everything is an object in Ruby. Each and every code…