Created
December 6, 2018 21:32
-
-
Save marek2901/959f595ac4b9920037df40d0f7d0f439 to your computer and use it in GitHub Desktop.
Lublin IT Ruby 101 Ask Me Anything
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 AskForAnything | |
def method_missing(method_name) | |
if /^for_(?<questions>.*)/ =~ method_name | |
answers = questions.split('_').map do |question| | |
if %w(and or).include? question | |
next | |
end | |
puts "What is your #{question}" | |
{ question => gets.chomp } | |
end.compact.reduce({}, :merge) | |
puts 'Hi nice to meet you, I did some research and it turned out:' | |
answers.each do |question, answer| | |
puts " Your #{question} is #{answer}" | |
end | |
else | |
super | |
end | |
end | |
end | |
ask = AskForAnything.new | |
ask.for_name_surname_and_age | |
# What is your name | |
# Marek | |
# What is your surname | |
# Dziewit | |
# What is your age | |
# 23 | |
# Hi nice to meet you, I did some research and it turned out: | |
# Your name is Marek | |
# Your surname is Dziewit | |
# Your age is 23 | |
ask.for_email_and_password | |
# What is your email | |
# [email protected] | |
# What is your password | |
# super_secret | |
# Hi nice to meet you, I did some research and it turned out: | |
# Your email is [email protected] | |
# Your password is super_secret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment