This week we focused on how to use Classes in Ruby. Classes are considered a blueprint of Ruby’s design. Since Ruby is an Object-Oriented programming language, classes are used to create objects. Once the class is created, the methods and information is organized inside of the array. Below I created a code snippet that shows how classes in Ruby work.
In the example above, created a class called ‘Books.’ I created a method to initialize the name of the book and the author.’@book_name = book_name’ is structure used to create variables. In this case, I created another method called ‘must_read’ which is used to set up the information that will print. As I am listing more than one book, this is more effective for avoiding repetition. To create a new object in the class, I use ‘Books.new()’ then type the new information into the parentheses. Then, I type the variable name that corresponds with the new object and pull the information from the must_read method.