###Meet the O.O.G.G.s The O.O.G.Gs are the Object Oriented Garden Gnomes. You don't want to mess with them, because they're the meanest, toughest, gnomiest gnomes in town.
We're going to build a Garden Gnome class so that we can make individual instances of Garden Gnomes that can terrorize front lawns around the neighborhood. Open the file garden_gnome.rb
and follow these instructions.
###Instructions
- Create a class called
GardenGnome
. - Garden gnomes have names. Add a reader and a writer method for name.
- Garden gnomes also have ages (They can live to 4000 years, in fact). Add a reader and a writer method for age.
- Little gnome fact: Some garden gnomes are allergic to gluten. Create an attribute
gluten_allergy
using a reader and writer method. - Everyone gnows that that gnomes are all born evil. As such, create an initialize method which sets
@personality = "evil"
Create a reader for the personality attribute (but no writer, because once an evil gnome, always an evil gnome). - Add an argument to your initialize method called
hat_color
and then use the argument inside the initialize method to set a gnome's hat color at the moment that it is created (using.new
). If the user doesn't give a hat color in the argument, it should default to 'red'. Create ahat_color
reader and writer to access this attribute. - Gnomes can take many evil actions. One of them is destroying the trees in a garden by chewing them up. Create a method
gnaw
that, when called, returns the value of "Gnawing on a tree!!!" - Create another action method called
shout
that returns the value of "GNARLY!!!" when called. - Create an action called
introduce_self
that returns the value of "Hello humans, my name is _________, I am _____ years old, and you'll rue the day you crossed me!". Blanks should be filled in with the gnome's name and age.
Once you've gotten all the learn tests to pass, practice creating instances of the GardenGnome
class by following these instructions:
- Create a new instance of the
GardenGnome
class and assign it to the variablegnome1
. - Create another instance of
GardenGnome
and set it's name to "Walter the Worst". - Create another instance of
GardenGnome
and set it's name to "James the Jerk" and its age to 3421. - Create another instance of
GardenGnome
and set it's name to "Alfed the Abhorrent" and its age to 579. Set its gluten_allergy attribute to true. (Alfred has terrible allergies.)
View Meet the O.O.G.G.s on Learn.co and start learning to code for free.