Need help? Chat now!

Hostwinds Blog

Search results for:

What is Ruby? Featured Image

What is Ruby?

by: Hostwinds Team  /  February 22, 2020

Who's seen the classic film entitled The Wizard of Oz? If you have, you may be familiar with Dorothy's iconic ruby slippers. Did you, by chance, know that the creators of The Wizard of Oz initially wanted the slippers to be silver? They certainly made the right choice by upgrading to ruby. Similarly, a bright mind by the name of Matsumoto once upgraded his coding experience by developing the programming language Ruby.

If you have yet to code with Ruby, you have found the perfect introductory blog post to give you some Ruby background before getting started!

What is Ruby?

Ruby is a programming language. To elaborate on that, Ruby is an object-oriented programming language.

What is Object-Oriented?

This means that all values within the code are treated as objects with characteristics defining them. Each element represents an object and has properties just like physical objects do. Additionally, each object has methods that are particular to it.

To elaborate on Ruby's identity even further, Ruby is known as a 'general purpose' language due to the diverse range of projects you can create using it. Come to think of it. Ruby is referred to as a lot of things, one being a 'multi-paradigm programming language.

Simplicity is the name of the game when it comes to Ruby. It is simple to type and read. To that end, Ruby is a high-level programming language.

What is a High-Level Programming Language?

Wait, we've asked this question before! The following excerpt is from a previous Hostwinds blog post entitled 'An Intro to Python.'

"Definition of High-Level Programming Language: A high-level programming language is one that closely resembles a language spoken by people. High-level languages make it easier to code because they are more intuitive than low-level languages."

READ MORE: An Intro to Python

Have You Heard of Ruby's Principle of Least Astonishment (POLA)?

This principle goes along with the whole 'simplicity' concept we've been harping on. POLA essentially means making things as uncomplicated as possible. Ruby syntax is reminiscent of the English language. Such being the case, it isn't astonishing that a specific command written in Ruby does what it does. This is why Ruby is so appealing to those who are new to coding.

On a similar note, Ruby has other principles that it has to live up to. For instance, Ruby is meant to be helpful for humans, not necessarily computers. In other words, Ruby was crafted to ensure that humans, the ones in charge here, not computer robots (which were made for the sole purpose of serving humans), have a user-friendly experience while working with Ruby. It doesn't matter if Ruby is user-friendly for computers because they are robots!

Ruby wears many hats. Yes, it's both high-level and object-oriented, but it's also a scripting language and an interpreted language. Are we getting too far ahead of ourselves here? Let's run through some quick definitions to be safe.

What is a Scripting Language?

A scripting language executes commands automatically through a specific run-time system.

What is an Interpreted Language?

Our 'Intro to Python' blog post covered this one for us: An interpreted language "[…]is translated to a format that a computer can understand at run-time. Accordingly, no compiling takes place […]. Rather, the code is executed right away at run-time."

Presently, Ruby is a very, very popular language that's mainly used to build web applications. Let's see how Ruby's journey down the yellow brick road all began.

A Little Ruby History

Ruby was first introduced to the world in 1995 by Yukihiro Matsumoto. Matsumoto, or 'Matz,' released Ruby version 1.0 in 1996. As stated above, Ruby is employed a lot for web programming, mainly because it was invented to increase productivity. How? Its uncomplicated and simplistic style and syntax, of course.

Here's How Ruby Came to Fruition: This is somewhat of a Goldilocks and the Three Bears story. Matsumoto built Ruby after realizing he wasn't satisfied with either Python or Perl. Python needed more object-oriented functionality as far as Matsumoto was concerned, while Perl required more power. Matz decided he wanted to work with a completely new programming language that was a hybrid between the best parts of Python and Perl.

Enter Ruby!

Ruby Syntax

Ruby's clean, concise, and compact syntax allows one to create programs a lot quicker than the average programming language. Parentheses, for instance, aren't a necessity. Ruby's syntax doesn't need much punctuation at all, for that matter. You don't even have to add a semicolon at the end of each segment of code. In that case, you could insert a line break between that chunk of code and the next to achieve the same effect.

This programming language happens to be case-sensitive. Identifiers are not even excluded from Ruby's case-sensitive rule. Identifiers are just the names given to various methods and variables.

Onto more syntax! Ruby uses blocks and defines them via braces and keywords. Furthermore, whitespace doesn't matter in Ruby. Therefore, you can begin coding with Ruby on whatever line you would like.

On a different note, you don't have to declare variables when you use Ruby. All of the instance variables in this unique language are entirely private. Ruby uses accessor methods to reveal the variables.

A Ruby Accessor Method Looks Something Like This:

Ruby 1 attr_reader

What are Variable Scopes?

Variable scopes refer to the areas in a program where certain variables are present. Ruby has local, class, instance, and global levels of varying scopes.

Getting a Little Bit More Intricate Here: Ruby supports first-class continuations. It would take a lot of time to unpack that one, but we highly suggest looking up the term. It's pretty fascinating.

There are many others where that came from.

Tip to Further Your Understanding of the Complex Things Ruby Can be Used For: Look up 'Metaprogramming.'

One More Tip: Look up 'Lexical Closures' and 'Parametric Polymorphism.'

Now we're ready to set up a little bit of Ruby code. First off, you should know that every Ruby file ends in '.rb.' Let's say our Ruby file is called 'myrubyfile.rb.'

If we want to display "Hostwinds loves you!" on a web page, for example, all you have to type is the following:

Ruby 1 puts "Hostwinds loves you!";

Now run this:

Ruby 1 $ ruby myrubyfile.rb

Guess what your page will display? You got it!

Hostwinds loves you!

If you would like to make comments in Ruby, add a '#' in front of the sentence(s).

Ruby 1 # Ruby comments go here!

Now, if you need to make several lines of comments, you can also type '=begin' before the comments and '=end' after like so:

Ruby 123456 =beginRuby comments go here!And here!And here!This could go on forever!=end

That is just a tiny glimpse of what Ruby looks like.

What is Ruby on Rails?

Ruby on Rails is Ruby's open-source library or framework. David Heinemeier Hansson developed such a software library. Ruby on Rails is a library that expands Ruby functionality.

Ruby on Rails is also called 'Rails.'

One of the cool things about Ruby on Rails is that you don't technically need to know Ruby like the back of your hand to understand the former. It certainly helps, particularly with syntax. However, it is not required. Ruby on Rails is responsible for the creation of fantastic applications such as Hulu and Shopify!

What is RubyGems?

RubyGems is a module manager for Ruby. You can pull from Ruby-supported software libraries (or applications) to expand Ruby's functionality.

Fun Fact: Each software library within RubyGems is referred to as a 'Gem.' Tens of thousands of Ruby Gems exist today.

Besides Ruby's standard library, the programming language supports modules such as HTTP, XML, JSON, and many others.

Ruby Features

Several features make Ruby unique and helpful.

Namely, the following:

Duck Typing:

Once more, we'll employ the help of our "An Intro to Python" blog piece to provide you with a few definitions here.

"Definition of Duck Typing: To properly define duck typing, allow us to explain the 'duck test.' If the object quacks and walks like a duck, it indeed a duck. This terminology is used within the realm of object-oriented programming because the object is defined by its properties and methods rather than its type."

Garbage Collection:

"Definition of Garbage Collection: Garbage collection is the method of tracking every single object stored in memory, then ultimately disposing of objects that aren't being used. While that definition doesn't even remotely cover the intricacies of this process, it will do for this blog piece. For more information about garbage collection in this context, we suggest looking up 'First Generation Object.'"

Dynamic Typing:

"Definition of Dynamic Typing: To type dynamically is to execute code at run-time, thereby skipping the extra step to compile the code."

More Features Include:

  • Operation Overloading
  • Strictly-Enforced Encapsulation
  • Exception Handling
  • The Use of Iterators
  • The Use of Meta-Classes
  • Inheritance
  • Linux user? Windows user? Ruby can run on both as well as both Solaris and Mac.

Developers can also combine Ruby with an Integrated Development Environment (IDE) to construct applications even faster.

Ruby's fantastic community isn't a feature, per se. Still, it is undoubtedly worth mentioning when listing the perks of working with this language. Ruby's large community works together by volunteering information and support to continue to innovate and improve each year. This lively crew even assists new developers in a variety of ways. In addition, the community updates members about Ruby news, such as recently-created libraries.

Before we conclude, are you curious to know what commonly-used applications have been made with Ruby?

Ruby Has Been Used To Make Prestigious Programs Including But Not Limited To :

  • Groupon
  • Github
  • Twitter
  • Simulations for High-Profile Corporations like Motorola
  • And way, way more!

Paint the Town Ruby

The best news about Ruby? It is an open-source programming language, meaning you can begin using it now at no cost!

So what are you waiting for? Let's all paint the town, Ruby, and try using this powerful object-oriented programming language ASAP!

P.S. Comment below if you would like Hostwinds to write a subsequent blog post about Ruby on Rails! Farewell, for now, folks.

Written by Hostwinds Team  /  February 22, 2020