Picking up Ruby Fast, as a Python Dev
Tags: ruby, python, codenewbie
Published: 2020-11-12 17:17:15

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
I know approximately zero Ruby. I’m very willing to learn."](https://dev-to-uploads.s3.amazonaws.com/i/1wn44vvskqqsp4mnjjwh.png)

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.

{% twitter 1326595442457632769 %}

[The Ruby quickstart guide](https://www.ruby-lang.org/en/documentation/quickstart/) 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](https://try.ruby-lang.org/) 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](https://try.ruby-lang.org/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.

```ruby
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")
```

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
So any place you see an each, you can substitute map"](https://dev-to-uploads.s3.amazonaws.com/i/kr3c7e27brh4rc385wqr.png)

## 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` |
| `true``false` | `True``False` |
| `'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](https://ruby-doc.org/gettingstarted/) and the [playground](https://try.ruby-lang.org/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](https://dev-to-uploads.s3.amazonaws.com/i/uy025kdaz8grj55ntjty.jpg)