Spice up a Ruby CLI app

Jb
3 min readFeb 16, 2021

The first week of flatiron is all about ruby. We were taught how to create classes, associations, and methods. Our very first project was to create a command line CRUD (create, read, update, and delete) application in ruby. Today I’m here to talk about the bare bones of setting up a cli application using ruby and adding a few touches to give your cli application a little more life.

Create a new ruby application by using the command rails new yourApplicationName. In this brief demonstration we will not be creating any controllers. Next we will create a few models with associations. In my project I created a cli application where students can sign up with a teacher of their choice and instrument of their choice. My application consisted of three models students, lessons, and teacher, all with their appropriate associations as seen here.

Once models, migrations, and associations are made we are ready to begin developing our cli application. In the bin file we will create a run.rb this will be used to launch our cli application in the terminal. Within the lib folder is where we will create a single class that will provide our crud methods. For example in my application I created a class called ScheduleApp. This class housed all the methods that included arrays of objects such as musical instruments to choose from and your choice of the level of skill you are currently at. We will then call this class in our run.rb file that we created in our bin folder. In the example below it also includes methods that are being called in the app variable that we also set to creating a new ScheduleApp. We call the run file by using the command ruby bin/run.rb in our terminal.

Now to spice up our cli application. First thing I did was created a huge title/banner for my application. I created another file in the lib folder with the sole purpose of creating a method. This method is text in quotes also known as ASCII art that is then used to be require_relative in our main ScheduleApp class. Here is my custom ASCII art,

In this method I have also used a command line tool called pastel which I required through gem ‘pastel’. With pastel you are able to change the colors and styles of texts you created such as prompts and banners. Create your own ASCII art and play around with the font colors in your own cli application, Happy coding! Feel free to reach out to me on linkedIn or github.

--

--