Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




RUBY - BASIC


Ruby

  1. Ruby is an Object Oriented Programming language developed in 1993, by Yukihiro Matsumoto of Japan.

  2. Ruby is a server-side scripting language just like Ruby.

  3. Ruby can be easily embedded into an existing HTML.

First Ruby Application


puts "Hello World";

Printing 'Hello World' is as simple as the above line.


Also the print statement can be written using the below statement :


print "Hello World";

Note : The only difference between 'puts' and 'print' is, 'puts' prints an extra line after each line whereas 'print' does not.

With puts


Example :



	puts "Hello World.";
	puts "A Beautiful City."


Output :



  Hello World.
  A Beautiful City.

With print


Example :



	print "Hello World.";
	print "A Beautiful City."


Output :



  Hello World.A Beautiful City.

Where do we write Ruby related code?


The codes in Ruby should be written inside a file with extension '.rb'.


So, we will be writing the above code to print Hello World inside a file named FirstApplication.rb.


FirstApplication.rb


Example :



puts "Hello World";



Now, to execute the above code, we have to type the following in the command prompt :


Ruby FirstApplication.rb

Output :



  Hello World