GA Week 1: Terminal, Git, Ruby
What a busy first week at GA WDI! It has certainly been demanding and challenging, but my knowledge definitely seems to be progressing and I may even be having a little bit of fun along the way!
This is my favorite project so far: Happitails. We were tasked with creating a sort of management system for an animal shelter, with intentionally vague guidelines. Essentially, the data is structured as:
Instances of class Shelter contain the shelter name and address, a hash for its clients and a hash for the animals currently at the shelter.
People instances have the usual people stuff, and a hash of pets that person owns.
Animal classes have a few attributes, and an array of toys the animal drools on and carries around the house proudly in its mouth.
The easy part was setting up these classes. I also produced a little text-based menu to allow for management of the instances. It consists of functions to:
Add or remove clients
Add or remove pets
Transfer pets between the shelter and client (as clients pick up pets or drop them off).
I did a better job streamlining my methods for this project. The cool part is there is there are just three methods to do all the above, and by sending methods with the #send method I could represent both picking up and dropping off, for example, with the client_action method. This is why I have:
object = (action == :drop_off && shelter.clients[which_client]) || shelter
in that method. This uses short-circuiting to create a ternary where if the client is dropping off, object becomes that client object (from the shelter.clients hash), otherwise object is the shelter itself. That means when we call the whats_left method to print the animals available, if the client is dropping off we see the pets in her pets hash (object is the Person instance), but if she's picking up we see the pets the shelter has available for adoption.
I thought it was really cool that at the end I could run the menu, instantiate myself through it as a new Person instance (the program uses the instance_variables method to dynamically collect the required data to initialize either a Person or an Animal) , also instantiate my childhood pet Gus the guinea pig, and then pick up Gus from the shelter. Hello again old friend!
















