Last active
May 26, 2016 16:54
-
-
Save lucasprag/2e529460b3bfbb411bace191b073a60c to your computer and use it in GitHub Desktop.
key chain with if statements
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 KeyChain | |
def initialize(door) | |
@door = door | |
end | |
def get | |
if door == :bedroom | |
generate_bedroom_key | |
elsif door == :front_door | |
generate_front_door_key | |
elsif door == :bathroom | |
generate_bathroom_key | |
end | |
end | |
private | |
attr_reader :door | |
def generate_bedroom_key | |
"algorithm of bedroom key" * 3 | |
end | |
def generate_front_door_key | |
"algorithm of front_door key" * 3 | |
end | |
def generate_bathroom_key | |
"algorithm of bathroom key" * 3 | |
end | |
end | |
# usage example | |
KeyChain.new(:bedroom).get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment