Learning to contribute. My first dive into open source led me to learn a little Ruby.

Jennifer Peavler
Jul 20, 2017 · 4 min read

I was recently given an assignment to jump into an open source codebase and contribute. It’s something that I have wanted to do, but have been…well, scared. After all, I am just a fledgling, I have only been coding for 6 months, what can I possibly contribute? My code at this point is all pretty stupid right? What if I mess up the codebase?

So, while I was still nervous jumping into someone else’s big scary codebase, I was glad at least have someone forcing my hand into the issue. Help at the risk of embarrassing myself or suffer the wrath of my instructor…I’ll take suffer the wrath most days, but today since I’m a good sport, I’ll take embarrassment.

Great, now I’m taking the leap, so I open the repo and low and behold, there is very little I actually recognize. Everything appears to be in Ruby and Angular…but, but, but….I WRITE JAVASCRIPT!!! Well the cookies are tough, so welcome to the start of my quest to learn about Ruby.

First thing that I learned, I already knew…the docs are my friend! Ruby docs are amazingly helpful. Thanks all you awesome doc writers! Because of them, in less than 5 minutes I went from intimidated to intrigued!

To get up and running in Ruby is actually very straightforward. Simply type the following into the terminal, and walaah, “Hello World!”

If you don’t have homebrew, here are some other ways to install Ruby. Ruby comes installed with a CLI and the command ‘irb’ starts it up.

Since I have a solid foundation in Javascript, I decided the easiest way to learn Ruby was to compare it to Javascript. Let’s look at variable declaration first.

Assigning a variable in Ruby
Declaring a variable in Javascript

In Javascript, there are three different ways to declare a variable and depending on scope and usage, the programmer must know which way to use. In Ruby, it’s as simple as assigning the variable a name and a number. One thing to also note is Ruby does not require semicolons, whereas in Javascript, it’s not necessarily required, but it is safer to include them as not to run into unintentional behavior when compiling.

Now let’s take a look at making a function;

Making a function in Ruby
Making a function in Javascript

Aside from syntactical differences, these two chunks of code are fairly similar. They both create a function named ‘hello’ that takes a parameter called ‘name.’ They both set the default value of that name to ‘World.’ They both output a greeting. The one major difference is there is a capitalize property native to Ruby that Javascript, as far as I’m aware, does not have. In JS, an extra function would have to be written in order to capitalize the first letter of a word.

Now let’s take a look at creating a class:

Creating a class in Ruby
Creating a class in Javascript

Again, other than the syntactical differences, these two chunks of code look very similar.

That should be enough code to get any curious mind excited to use Ruby. If you already have a fundamental knowledge of Javascript, Ruby should look fairly familiar. If you are learning Ruby as your first language, the documentation is outstanding. Take a look at these docs to get started!

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade