Skip to content

Instantly share code, notes, and snippets.

@dylanerichards
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save dylanerichards/e4486818cb4b9a467e8e to your computer and use it in GitHub Desktop.

Select an option

Save dylanerichards/e4486818cb4b9a467e8e to your computer and use it in GitHub Desktop.
For the haters
# Save Person instances
# Ask use who he is
# Display proper questions
# We have a set of people.
# Two sets of questions
# We want to give a set of questions to each of those people based on their age
#
class Person
attr_reader :age
def initialize(attrs = {})
@name = attrs.fetch(:name)
@age = attrs.fetch(:age)
end
def question
Question.generate_question(self)
end
end
class Question
QUESTIONS_FOR_YOUNGINS = [ "What's the capital of New York?", "What time is it?" ]
QUESTIONS_FOR_NECKBEARDS = [ "Yeah?", "Cheech?" ]
def self.generate_question(person)
if person.age > 20
print_questions(QUESTIONS_FOR_NECKBEARDS)
elsif person.age < 20
print_questions(QUESTIONS_FOR_YOUNGINS)
end
end
def self.print_questions(list)
list.each_with_index do |question, index|
puts "#{index + 1}: #{question}"
end
end
end
randy = Person.new(name: "Randy", age: 19)
dylan = Person.new(name: "Dylan", age: 21)
p dylan.question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment