Ticker

6/recent/ticker-posts

Ruby Programming Language

 



Ruby is an interpreted, high-level, general-motive programming language which helps more than one programming paradigms. It became designed with an emphasis on programming productiveness and simplicity. In Ruby, the whole thing is an object, consisting of primitive information types. Ruby is dynamically typed and makes use of rubbish series and just-in-time compilation. It helps more than one programming paradigms, consisting of procedural, object-orientated, and useful programming. According to the creator, Ruby became inspired via way of means of Perl, Smalltalk, Eiffel, Ada, BASIC, and Lisp.

What is Ruby?

Ruby is an open-supply object-orientated scripting language invented withinside the mid-90s via way of means of Yukihiro Matsumoto. Unlike languages together with C and C++, a scripting language doesn’t speak immediately to hardware. It’s written to a textual content report after which parsed via way of means of an interpreter and became code. Object-orientated languages, on the opposite hand, get away portions of code into gadgets that may be created and used as needed. You can reuse those gadgets in different elements of the program. Yukihiro desired to create a scripting language that leveraged object-orientated programming and growth code reuse to assist accelerate development. And so the Ruby programming language became born, the usage of easy language and syntax to address information and common sense to remedy problems.

What can Ruby be used for? The Ruby programming language is a particularly transportable general-cause language that serves many purposes. Ruby is amazing for constructing laptop applications, static websites, records processing services, or even automation tools. It’s used for net servers, DevOps, and net scraping and crawling. And while you upload withinside the capability of the Rails utility framework, you could do even more, particularly database-pushed net applications.

The BEGIN statement is used to reveal a piece of code that must be called before the program can run.

Syntax:

BEGIN
{    # code written 
}

Similarly, END is used to reveal a piece of code that must be called at the end of the program.


Syntax:

END
{  # code written 
}

Example

# Ruby program of BEGIN and END

puts "Main body program"

END 

{

  puts "END program"

}

BEGIN 

{

   puts "Start Program"

}

Output:

Start Program

Main body program

Ruby Programs/examples:

This segment consists of solved Ruby Programs/examples on numerous subjects inclusive of fundamental programs, conditions & manipulate statement-primarily based totally programs, looping programs, array & string programs, shape programs, function & package-primarily based totally programs, etc. with examinations and outputs. Ruby application to print Hello World!

Printing Hello World! in Ruby: This is the primary ruby application wherein we're going to print a easy message (Hello World!) the use of print and places commands. To print text, we use following methods,

To print text (Hello World! Or anything else), we use following two methods,

1. puts : This function  put string. It adds a newline after the string.

2. print : The functionality of this method is similar to that of Put but it does not explicitly add new lines like Put.

Variables used: No variables are required as we only have to print the statements. We don't have to store anything.

Ruby code to print "Hello World: My Frist Program "

=begin 
Ruby program to print Hello World: My Frist Program.
=end
puts "Hello World: My Frist Program"
print "Hello World: My Frist Program"
puts "Hello World: My Frist Program "

Output

Hello World: My Frist Program
Hello World: My Frist Program Hello World: My Frist Program

Code explanation:

This example to print a string "Hello World: My Frist Program" in Ruby programming language.
This uses the puts and print methods to print the output "Hello World: 
My Frist Program" using these methods.

the output that the print method is not providing a newline & 2 statements printing together.

 


    



Post a Comment

0 Comments