I think learning Ruby has three parts:
- OOP + SOLID in Ruby
- Ruby Syntax
- Idiomatic Ruby
What follows assumes you already know how to program in any other programming language. If this is the first time you are learning to code, then that is another path and I will write about it some day.
I would start in the following way:
- Ruby Syntax: First, read a bit about the Ruby syntax. You can find a short introduction to Ruby. (shameless plug) I tried to collect a lot of resources here, but you can also find some resources here. Do some small exercises if you feel like it just to get the syntax.
- Watch some videos of Sandi Metz. Here is a list of Sandi Metz videos for that. I recommend starting with SOLID Object-Oriented Design by Sandi Metz. Some things might make sense, some not. No worries, this is just a kind of priming your way of thinking about how to code in Ruby
- After watching one video go ahead and try to work on some learning project in Ruby. Do the first version of that that should work. Here is an example: Do an ATM simulator in Ruby. Or a Daily Quote CLI that should serve one quote daily.
- Push that project to Github and Gitlab.
- After you do the first version, install Minitest and try to redo that project but TDD style. So first, you will write a test and then make that test pass. Do this on a separate branch and open an MR/PR with it.
- Now, after you rewrote that project with tests, go ahead and rewatch the SOLID Object Oriented
- After watching, go open Github/Gitlab and review your code and try to add comments on what you think should be changed. That PR/MR done previously will help with this.
- Here is how to do the review: First, think about one of the principles you saw explained in the video and read your PR/MR, and add comments there with what to refactor to follow that principle. Then think about the second principle explained and then reread the code and add comments about this second principle. This is called perspective-based review, and it works better when you focus on one thing at a time.
- When finished with your review, go ahead and refactor based on the comments you added there.
- Watch this video Rules, by Sandi Metz and then go ahead and do the same process: Do the review and then refactor your code again.
- Then watch this video Aloha Ruby Conf 2012 Refactoring from Good to Great by Ben Orenstein and again do the same process: review + refactoring
At this point, you will know Ruby Syntax and OOP principles in Ruby.
It is time to go deep into idiomatic Ruby:
- I recommend first reading this https://www.poodr.com/
- Then I recommend you to read this https://www.packtpub.com/product/polished-ruby-programming/9781801072724
You don't need to read those books from start to finish. I recommend reading a chapter and doing a code review, and then refactoring.
Then you can read some style guides, but you can search and read more of them:
See which style guide makes sense for you now, and then go ahead and refactor your code to match one of them. Do not try now to mix them, but just take one and refactor your code to follow the guide.
After doing this, it is time that you start using static analysis tools:
- Install Rubocop and see if any of the style guides that you read has a Rubocop configuration. Use it with Rubocop.
- Install Ruby Critic and run it and try to fix reported issues.
From now you can start experimenting freely with Ruby and see what you like, what your style is what makes you happy.
Follow me on Twitter @lucianghinda where I share/retweet mostly Ruby and Rails content
I also publish a newsletter with Ruby and Rails fresh content at newsletter.shortruby.com - in case you want to stay up to date with what is happening in Ruby and Rails world.
Top comments (0)