Ruby is Pretty Neat

Cpan
3 min readAug 23, 2021

Last week we went over Ruby’s basics; making models, connecting our backend to our frontend. Ran through the basics of inheritance for classes etc, etc. All the OOP good stuff. We’ve only scratched the surface of what ruby has to offer. I took the time over the weekend to lookup some interesting ruby Gems that can be pretty useless when we’re doing this phases’ projects.

we’ve actually already used some of Ruby’s most popular gems such as rake, rspec, bundler to help us debug, test, and manage packages we need to import for our labs. But there’s so many interesting gems out there. Here’s just a few gems that seemed really interesting.

Devise

Devise is an authentication gem that provides you a very simple way of authenticating users via email/password, mobile number. Composed of 11 different modules:
Database Authenticatable,
Token Authenticatable,
Omniauthable,
Confirmable,
Recoverable,
Registerable,
etc..
You can read the full list of the different modules you can import from this gem here: https://www.rubydoc.info/gems/devise/2.2.8. Most webapps that host some DB will probably have a login/register. This gem makes it incredibly easy to create the backend for that feature. For example, if you want to check weather if a password is valid. You’d find the user from the user table through activerecords and simply use their built in .vlaid_password? instance method.

User.find(1).valid_password?('password123')         # returns true/false

Each password in the DB is encrypted and this method provides you a way to authenticate with that encryption.

Apexcharts

This was pretty surprising, I didn’t think that apexcharts would have ruby gem. When I was looking through some interesting graphics based Ruby Gems, this one popped up. ApexCharts is a very simple and easy to use library that provides interesting dynamic data visualizations. I used it for the react project would 10/10 would recommend using it.
https://github.com/styd/apexcharts.rb

Better_errors

Debugging your code is probably the most stressful part of being a developer. When you’re writing a block of code and you’d expect it to run this a specific way but soon discover that once you do run it, it doesn’t perform as expected. In ruby when this happens, it might be intimidating looking at the error message. Better_errors ruby gem gives you a better visualization of where the error is happening. It’ll also probably be better on your eyes as well.

It provides a full stack trace; each controller/model file is neatly stacked on top of each other. Each stack is clickable allowing you to see exactly where in the source code the error is happening. Each file links directly to your source code. It’s also way better on your eyes. I would 100% look at this any day compared to the default.

DelayedJobs

DelayedJobs is interesting in the sense that it can help you offload a lot of client-side processing to the back-end. This is similar to scheduling task in jenkins or in directly in shell where you can schedule a script to run at specific time to handle a bulk task that would otherwise to done at the moment. This can be pretty helpful if you want to run a backend task that shouldn’t affect user experience. The possibilities can be limitless but the basic principle that I can think of for this is when a user stores a set of data. For example; let say you run a company that monitors user health information. Doctors’/nurse would log information for that user. The next day, the home page for that user would show a detail list of possible complications. You can probably also allow end users to force run bulk data using delayedJobs. Possibilities are endless. https://github.com/tobi/delayed_job

That’s it for now, There’s countless gems out there but these are the ones that stuck out to me.

--

--