Last active
December 25, 2015 18:09
-
-
Save rosiehoyem/7017970 to your computer and use it in GitHub Desktop.
Refactoring Case Statements and Recycling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recycle | |
def initialize | |
@plastic_bin = [] | |
@glass_bin = [] | |
@paper_bin = [] | |
@metal_bin = [] | |
@landfill_bin = [] | |
@plastic_types = ["num_1", "num_2", "num_3", "num_4", "num_5", "num_6", "num_7"] | |
@glass_types = ["clear", "color"] | |
@paper_types = ["paper", "cardboard"] | |
@metal_types = ["aluminum", "tin", "copper"] | |
end | |
def recycle_bin(trash) | |
case | |
when self.plastic_types.include?(trash) | |
self.plastic_bin << trash | |
when self.glass_types.include?(trash) | |
self.glass_bin << trash | |
when self.paper_types.include?(trash) | |
self.paper_bin << trash | |
when self.metal_types.include?(trash) | |
self.metal_bin << trash | |
else | |
self.landfill_bin << trash | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment