DEV Community

Vicki Langer
Vicki Langer

Posted on • Updated on

Picking up Ruby Fast, as a Python Dev

So, I've been working with (read: learning and building projects with) Python for the last year and a half or so. It's been great. I like it, but who doesn't like their first language? Anyway, I'm in the market looking for jobs, and only knowing or being familiar with one language is kinda limiting. I wanted to add "what I'm willing to learn" on my resume, LinkedIn, and so on. That would open up more opportunities.

Why Ruby?

So, why Ruby? I don't have any fancy tech bro reasons. It seemed popular enough. Ruby has been around a while. Most importantly, I'd heard the syntax was rather similar to Python. So, basically, I took people's word for it that it would be a reasonably simple transition.

So, I had made a post on a discord community in our "Hire Me" channel about how I'm currently underemployed and looking for something better.

Screenshot from Discord chat"@Vicki (vicki_langer) How much Ruby do you know? I'm looking for a junior Ruby Dev." Then my response "Yesterday at 9:24 AM<br>
I know approximately zero Ruby. Iā€™m very willing to learn."

So, here I am learning some basics and hoping that will be enough to get in at a job that sounds pretty damn exciting.

How was I gonna learn fast?

This was legitimately just yesterday. I pulled up the Ruby docs and saw they had a quickstart guide.

The Ruby quickstart guide is fantastic! I could only wish Python had something similar. They for real ELI5 and it's wonderful! I really thought it would be harder to get started with Ruby. Then! It got even better. The docs have a try-Ruby-in-browser thing and it has all sorts of practice stuff. It's set up a bit like Free Code Camp.

I used their little browser editor/playground to throw together an example with the bits and pieces I picked up.

If you've seen any of my other posts, you know I can't fathom using examples that are based on math or crappy variables like x, i, foo, or baz. So, expect the same here.

def give_Cat_Snacks(name = "the cat")
  snack_Level = 0  # according to the cat
  if snack_Level < 10
    until snack_Level == 10 do
      snack_Level += 1
      puts "Gave #{name.capitalize} some snacks"
      puts snack_Level
  elsif snack_Level > 10 and snack_Level < 20
      snack_Level += 1  # just enough to pretend you added snacks
      puts "pretended to give #{name.capitalize} snacks"
      puts snack_Level
  else
      puts "tell #{name.capitalize} no, quit lying"
end

give_Cat_Snacks("puppy")
Enter fullscreen mode Exit fullscreen mode

Now, the function wasn't working, but I threw it in the discord chat anyway. I got tons of great feedback. Here's what I got:

  • I messed up my comparison. Should've been ==
  • Could use 10.downto(1).map instead of until snack_level == 10
  • map can be substituted for each and it's better for speed

Screenshot from discord: I said: "10.downto(1).map I've never used maps" I got a response " maps behave kinda like JS, normally you can always use map instead of each and it's generally preferred because Enumerators are twice as fast as loopers because one is written in C using optimizations and the other isn't<br>
So any place you see an each, you can substitute map"

A Few Quick Points of Difference

Ruby Python
puts "meow" print("meow")
print "woof" print("woof")
def give_Cat_Snacks def give_Cat_Snacks():
require import
elsif elif
truefalse TrueFalse
'raw string' r'raw string'
spacing doesn't matter spacing is mandatory
hashes dictionaries
parentheses optional parentheses required

Okay, I need to stop writing and go back to the docs and the playground to learn some more. In the meantime, let me go give this ungrateful cat some snacks. He is STILL claiming zero snacks are in the bowl

adorable tuxedo cat staring at a bowl with some snack in it, acting like there are absolutely zero snacks in the bowl. just in case you couldn't tell, my cat is a damn liar

Top comments (5)

Collapse
 
mathewthe2 profile image
Mathew Chan • Edited

Love your story! I'm also learning Ruby as a Python developer and I find the exercises from this website quite helpful. And since I started Python with Django Girls, I tried Rails Girls to build a Rails app and I enjoyed their detailed hands-on explanation as well!

Collapse
 
vickilanger profile image
Vicki Langer

As soon as I'm done going through try.ruby-lang.org/ I will go through the site you're talking about. It looks super friendly. (and I'm seriously wondering where all of this is for Python, because I definitely didn't see anything that comprehensive and friendly) side eyes python

I used Django Girls too! I had no clue Rails Gitls existed. I'll keep that in mind if I need or decide I want to pick up Rails too.

What made you start working with Ruby?

Collapse
 
mathewthe2 profile image
Mathew Chan

Glad that you find the site friendly! To be honest, I looked at Ruby because several companies I'm applying to uses it. I still prefer Python for my own project though.

Collapse
 
gravesli profile image
gravesli

Thank you for sharing.

Collapse
 
aaronmccollum profile image
Aaron McCollum

Good tip on the beginner guide on the docs! Enjoyed your article. Keep it up!