(This is the final lesson in Ruby…?)
It’s past midnight now, but starting today (Thursday), we will start learning Git and GitHub. The problem is, I already learned Git and GitHub last year when I took their WordPress Development blueprint program. I guess this means, more time doing some supplemental learning of the basics of Ruby, right? Yup. Right on.
In Day 12, we learned the two final basics of Ruby: attribute accessors and symbols. I didn’t post this code on my previous post, but this particular one was my assignment when we learned object orientation, ancestry and inheritance, and class methods and class variables.
Below was my object orientation sample code that I did back at Day 11. Yes, I’m using the manga topic as an example.
With atrribute accessors, I’m using the
attr_accessor method to shorten all of that code into something much simpler and cleaner. Here is how we use that method to refactor the code shown above:
The attribute accessor is the “set” and “get” (from the original code above) combined as one. This is a very useful method, especially when there’s going to be a lot of user input to be collected, like my entire collection of manga, for example.
Last, but not least, we learned about symbols. You see the classes
:title, :mangaka, :genre having colons in front of them. That’s what they are. The colons are called symbols. Unlike variables, symbols don’t really mean anything. Just using symbols in front of classes reminds Ruby on what to do with them. If we call them out using the
puts command, nothing will happen. Along with symbols, we also learned about hashes. Hashes are kind of like arrays, but they store a list of info regarding one object. With symbols combined, collecting data from user input is a lot easier and cleaner to refactor.
Again, the whole manga theme:
The test result of this script is the terminal screenshot shown at the top of this entry.
And that would be it for the basics of Ruby (or probably basics in general programming). Now I need to do more supplement studying.
Now that I thought of it, maybe I should start opening a tutorial series about Git and GitHub as I go along my Git/GitHub class? What do you all think?