A Beginner's Guide to Ruby Programming Language

The logo, selected as winner of the Ruby Logo Contest

Tom Schaub / Wikimedia Commons

Ruby is unique among object-oriented scripting languages. In a sense, it's a purist's language for those who love object-oriented languages. Everything, without exception, is automatically an object, whereas in other programming languages this isn't true.

What is an object? Well, in a sense you can think of it in terms of building a car. If you have a blueprint for it, then an object is what's built from that blueprint. It contains all the attributes that the object holds (i.e. make, model, color) and the actions it can perform. But, even as a pure object-oriented language, Ruby doesn't sacrifice any usability or flexibility by leaving out features that aren't expressly related to object-oriented programming.

Designing Ruby

Ruby's architect Yukihiro Matsumoto (known simply as "Matz" on the web) designed the language to be simple enough for beginning programmers to use while also powerful enough for experienced programmers to have all the tools they'd need. It sounds contradictory, but this dichotomy is owed to Ruby's pure object-oriented design and Matz's careful selection of features from other languages such as Perl, Smalltalk, and Lisp.

There are libraries for building all types of applications with Ruby: XML parsers, GUI bindings, networking protocols, game libraries and more. Ruby programmers also have access to the powerful RubyGems program. Comparable to Perl's CPAN, RubyGems makes it easy to import other programmers' libraries into your own programs.

What Is Ruby Not?

Like any programming language, Ruby has its downsides. It's not a high-performance programming language. In that regard, Python's virtual machine design has a huge advantage. Also, if you're not a fan of the object-oriented methodology then Ruby isn't for you.

Though Ruby does have some features that fall outside the realm of object-oriented languages, it's not possible to create a non-trivial Ruby program without using the object-oriented features. Ruby doesn't always perform as well as other similar scripting languages in raw computing tasks. That being said, future versions will address these problems and alternate implementations, such as JRuby, are available as a workaround for these issues.

How Is Ruby Used?

Ruby is used in typical scripting language applications such as text processing and "glue" or middleware programs. It's suitable for small, ad-hoc scripting tasks that, in the past, may have been solved with Perl. Writing small programs with Ruby is as easy as importing the modules you need and writing an almost BASIC-like "sequence of events" type of program.

Like Perl, Ruby also has first-class regular expressions, which makes text processing scripts a snap to write. The flexible syntax also aides in small scripts. With some object-oriented languages, you can get bogged down with verbose and bulky code, but Ruby leaves you free to simply worry about your script.

Ruby is also suitable for larger software systems. Its most successful application is in the Ruby on Rails web framework, software which has five major subsystems, numerous minor pieces and a plethora of support scripts, database backends, and libraries.

To aid the creation of larger systems, Ruby offers several layers of compartmentalization, including the class and module. Its lack of superfluous features allows programmers to write and use large software systems without any surprises.

What Skills Would Be Helpful for Learning Ruby?

  • A solid understanding of object-oriented concepts. Ruby is an object-oriented language and the object-oriented features are used throughout. Without this critical skill, you'll be struggling as a Ruby programmer.
  • A bit of functional programming knowledge. This is a plus as Ruby uses the block or "closure" extensively. Not having this ability isn't insurmountable, though. Creating blocks is a feature that can be learned easily enough while learning Ruby.
  • A bit of navigational know-how. The primary way of running a Ruby script is from the command-line. Knowing how to navigate directories, run scripts and redirect input and output are essential skills to Ruby programmers.

Applications and Tools Needed for Ruby

  • The Ruby interpreter
  • A text editor such as Notepad++, Scite, or Vim. Word processors such as Wordpad or Microsoft Word are not suitable.
  • Command-line access. Though the details of this differ from platform to platform, Linux, Windows, and OSX all have this available without any extra downloads or software installation.
mla apa chicago
Your Citation
Morin, Michael. "A Beginner's Guide to Ruby Programming Language." ThoughtCo, Feb. 16, 2021, thoughtco.com/what-is-ruby-2907828. Morin, Michael. (2021, February 16). A Beginner's Guide to Ruby Programming Language. Retrieved from https://www.thoughtco.com/what-is-ruby-2907828 Morin, Michael. "A Beginner's Guide to Ruby Programming Language." ThoughtCo. https://www.thoughtco.com/what-is-ruby-2907828 (accessed March 28, 2023).