DEV Community

Cover image for My beloved Ruby Cheat Sheet

My beloved Ruby Cheat Sheet

Eric The Coder on December 14, 2020

Follow me!: Follow @EricTheCoder_ Here is my cheat sheet I created along my learning journey. If you have any recommendations (addition/subtract...
Collapse
 
tommulkins profile image
Tom Mulkins

Thanks for putting this out there.

I have one suggestion:

Consider making "dealing with Nil values" its own section. :)

Collapse
 
dexter38 profile image
Pascal Gautherot • Edited
# I have some fruits...
fruits = <<END_OF_FRUITS
Apple Orange Banana
Pineapple Strawberry Apple
Orange Apple Strawberry
END_OF_FRUITS
# "Apple Orange Banana\nPineapple Strawberry Apple\nOrange Apple Strawberry\n"

# I want to split with space and CR
fruits.split(/ |\n/)
# ["Apple", "Orange", "Banana", "Pineapple", "Strawberry", "Apple", "Orange", "Apple", "Strawberry"]

# I want to make a GROUP BY like a DB
fruits.split(/ |\n/).tally
# {"Apple"=>3, "Orange"=>2, "Banana"=>1, "Pineapple"=>1, "Strawberry"=>2}

# How many Apples can I eat this morning?
fruits.split(/ |\n/).tally["Apple"]
# 3
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leewynne profile image
Lee

This is great!

Collapse
 
norrismei profile image
Norris Mei

Thank you for this summary! I'm brushing up my Ruby skills and this cheat sheet jogged a lot of things for me.

For the exception handling part, I think you meant 1 / 0 for ZeroDivisionError. It's written as 0 / 1 in two lines and one comment, which is just 0 and shouldn't produce an error.

Collapse
 
khaireddine19 profile image
Khaireddine Hamdi

This article is very great, thanks

Collapse
 
sylwiavargas profile image
Sylwia Vargas

Oh wow!! I love this. I’m going to read it in depth tomorrow to my morning coffee!

Collapse
 
puzanov profile image
Oleg Puzanov

This is truly helpfull. Also want to have the same for PHP and Python

Collapse
 
leewynne profile image
Lee

Have added it to my snippets :D

Collapse
 
rebecca_ariss_61f39d1af4c profile image
Rebecca Ariss

I had never heard of screaming snake case until today and I am so delighted to find out about it 😂

Collapse
 
ericchapman profile image
Eric The Coder

Updated the cheat cheat with couples more info related to array contact and couples other things.

Collapse
 
vildulv profile image
Alex

Thanks! Very useful.

Collapse
 
ishimwezachee profile image
zachee

Thank you so much for this