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.
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")
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 ofuntil snack_level == 10
-
map
can be substituted foreach
and it's better for speed
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 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
Top comments (1)
I am also learning Python to program block blast. A game that I love very much, my dream is to become a famous game programmer.