Build your own Ruby gem

Did you know that ruby is one of the hardest gemstones?
Examples;
“()” => true
“)(()))” => false
“(“ => false
“(())((()())())” => true

Creating the Gem scaffold

We are going to use Bundler gem. Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Be sure that you have it via $ gem install bundler command.

Auto-generated scaffold files by Bundler

Testing with RSpec

Our test file is created when we scaffolded the project, it is located atspec/CheckParans_spec.rb , let’s add some simple tests to that;

Build the Gem

Only the easiest part left now, we just need to run the following command;

Use the Gem

Since the gem is installed we can require it any rb file we wish

--

--

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
Ali Erbay

Ali Erbay

7 Followers

Full Stack Developer BDD/TDD || Ruby on Rails || React || React Native || NodeJS || Express https://github.com/kermit-klein