What is Ruby and Ruby methods that I found challenging?

diiiiana99

diiiiana99

Posted on March 14, 2022

What is Ruby and Ruby methods that I found challenging?

In previous blog postings, I discussed how difficult it was for me to understand and apply the material. Well, in comparison to the others, I'd say this step was the most difficult. This step necessitated a great deal of concentration, repetition, and, most importantly, perseverance. I'm happy to report that I made it through the ordeal and learnt a lot! In this blog, I will be discussing how Ruby methods are structured and implemented, as well as the strategy I followed to better understand them!

Active Record Methods was the subject on which I spent the most time studying. At first, I thought that writing these methods would be simple. It was in certain circumstances! It didn't take me long to figure out simple ways like retrieving an ordered list of instances or finding a single instance by a certain key. When I started learning more advanced techniques, such as identifying the most popular instance of a class or employing helper methods within other methods, I became frustrated. That's when I started having problems.

Image description

This strategy was unquestionably difficult to implement appropriately. Figuring out what my end result needs to be and then thinking about all of the various steps/code it might take to get there was one of the most beneficial abilities I utilized to go through this.

Image description

The helper method I utilized in the most popular method to help me get to my ultimate result is shown here. Originally, this method was used to determine the number of books written in a given genre. The wonderful thing about some of these simple techniques is that they can help simplify the code for more sophisticated ones. If you look at the first snip, you'll see what I mean. In the first line of code, you can see how this helper method is used. The first line of code is in charge of calculating the total number of books in each genre and returning them as an array in the books total variable.

The total number of books for each genre instance is calculated using my book count function. The second line of code locates the index with the largest books total value and saves it to the idx variable. The final line of code loops through the whole array of genre instances and returns the genre that was discovered and saved in the idx variable.

It's critical to approach these types of approaches line by line, paying great attention to what each line will yield and how that will help you get closer to your desired final result. Solving them became lot easy once I started thinking about each strategy in this way!

💖 💪 🙅 🚩
diiiiana99
diiiiana99

Posted on March 14, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related