A jewel among the rest, Ruby

An introduction to a language with much history and which is still used today.

Background

Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto in the mid 1990’s in Japan. Everything in Ruby is an object except the blocks but there are replacements as well such as lambda. Ruby has similar syntax to many programming languages like C and Java. It’s a great introduction to many other languages, once yoy learn it many others become easier to take on. The objective of Ruby’s development was to make it act as a sensible buffer between programmers and the underlying computing machinery.

Ruby is an interpreted scripting language meaning most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. Ruby also has access to its RubyGems and libraries.

Getting started with Ruby:
1. Your Compiler:
Before starting programming in Ruby, a compiler is needed to compile and run our programs. There are many online compilers that can be used to start Ruby without installing a compiler.

2. Programming:
To program in Ruby is easy to learn because of its similar syntax to already widely used languages.

Writing program:
Programs can be written in Ruby in any of the widely used text editors, my preference is Visual Studio Code and when you save the file you add the extension .rb

There is no such thing as a perfect programming language but some can come close. All languages have some advantages and disadvantages. Obviously Ruby is no exception and its age itself might even put it at a disadvantage.
Pros Ruby:

  • Code written in Ruby minimizes the lines, has better code readability and is powerful, best for industry standards.
  • Ruby allows simple and fast creation of Web application resulting in simpler code.
  • Ruby is free! Meaning Ruby is free to copy, use, modify, allowing programmers to make necessary changes and use it when required.
  • Lots of libraries and gems!

Cons of Ruby:

  • The code written in Ruby is harder to debug, it can generate at its runtime making it difficult to read while debugging.
  • Ruby does not have a plenty of informational resources as compared to other programming languages.
  • Being an interpreted scripting language, they are usually slower.

Applications:

  • Ruby can be used to create web applications. It is one of the higher ranked technology’s at present to create web applications.
  • Ruby offers a great feature called Ruby on Rails (RoR). It is a web framework that is used by programmers to speed up the development process and save time.

1.SetUp :

After installing Ruby open your text editor and save the program with ‘.rb’ extension. You can now use your terminal and type : ruby ‘file.rb’ whatever the file may be named and wherever it is, the program will be compiled.

2. Your first program
puts is used to print something on the console in Ruby.For something like a string

puts "Hello World"
puts "Hello Reader"
puts "Lets learn Ruby"

3. Comments

You can comment out one or multiple lines of code easily. Like with every language it is doable and in Ruby you use it using the pound character. It can go anywhere as long as it is in front of the line of code.

  • =begin, =end are used for multi-line comments

4. Mathematics: Simple arithmetic can be carried out within the puts statements.In ruby we can use a puts statement and #{Arithmetic problem}

The use of #{ } is how you insert Ruby computations into text strings.

puts "Victor sold #{50+150/4} Sneakers last week"
It'll be solved and printed out the correct way

Output : Victorssold 50sneakerslastweek

5. Variables and Names : Variables in ruby are the same as any other dynamic programming language. Ruby will automatically know its type.

cats = 50
dogs = 30
puts "There are #{cats} cats and #{dogs} dogs."

Output: There are 50 cats and 30 dogs.

6. Getting input

  • ‘gets.chomp’ is used to take input from user. It allows the user to be input their own data and what they want
  • ‘print’ can be used instead for ‘puts’ to print without a new line.
print "How old are you ? "
age = gets.chomp
puts " You are #{age} year old"

These are some of the most basic topics of Ruby that are essential for an introduction to the Ruby programming language. Ruby is a good language for application development, although some of its downsides lead companies to different alternatives. Its a great language to know and have under the hood and its syntax is noticeable in many others.

Full Stack Software Engineer || Entrepreneur at heart , engineer by training. Comedian in the eyes off my peers.