Skip to content

Instantly share code, notes, and snippets.

@rosiehoyem
Last active December 25, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosiehoyem/7017970 to your computer and use it in GitHub Desktop.
Save rosiehoyem/7017970 to your computer and use it in GitHub Desktop.
Refactoring Case Statements and Recycling
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