Utilizing RubyGems for 2D Gaming

With my first project for Flatiron School coming up I was definitely feeling a little lost, how could I make a CLI (Command Line Interface) database application more interesting than just characters on the screen? With RubyGems, of course! But more specifically, the Ruby 2D gem!

But First of All…What is RubyGems???

via https://guides.rubygems.org/

Basically, a Ruby gem is an open source library of Ruby code. It means that programmers can utilize the code written in the gem without having to write it out themselves! Gems are great because programmers like to be efficient, so it makes sense that the unofficial slogan of software developers is DRY (Don’t Repeat Yourself).

And that brings us to…

(drumroll please!)


What’s the big deal with Ruby 2D?

Ruby 2D enables programmers to create 2D games, visualizations, and applications with just a few lines of code! With Ruby 2D, you can create a game console, add music, add images, and even create animations in as little as 5 short lines of code!

Yeah, me too

Ruby 2D Setup

Installing is a simple process, detailed here for all operating systems, but I’ll run through the process for macOS:

To install Homebrew: type the following into your terminal

Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.

Then install Ruby:

How to set up your Ruby environment on the Mac

Once that’s all set up: install the Ruby 2D gem!

Ruby 2D gem installation code
We’re ready to code!

Making Something Interesting with Ruby 2D

I’m going to walk you through one of the simpler things we can do with Ruby 2D, we’ll be creating a (rather colorful) triangle.

  • First we’ll create a new Ruby script, ‘triangle.rb’ and write the following lines of code which will give us an empty window:
  • To spruce it up a bit we’ll add a little more code to give our window a name and describe what our triangle should look like:
  • After saving our script, we run it on the command line with the following code:
ruby triangle.rb
ruby triangle.rb
  • Then we’ll end up with this lovely ombre triangle:

Kudo’s to you! You’ve dipped your toe into the waters of Ruby 2D!👏👏👏👏

Try changing the colors of the triangle or try something more complex like creating an animation and let me know how it goes!

A standing ovation!


To check out Ruby 2D for yourself: Ruby 2D

For more on CLI:

For more on RubyGems:

Software Engineer👩🏾‍💻. Flatiron School Alum👩🏾‍🎓.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store