Skip to content

Instantly share code, notes, and snippets.

@marek2901
Created December 6, 2018 21:32
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 marek2901/959f595ac4b9920037df40d0f7d0f439 to your computer and use it in GitHub Desktop.
Save marek2901/959f595ac4b9920037df40d0f7d0f439 to your computer and use it in GitHub Desktop.
Lublin IT Ruby 101 Ask Me Anything
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
# marek.dziewit@intive.com
# What is your password
# super_secret
# Hi nice to meet you, I did some research and it turned out:
# Your email is marek.dziewit@intive.com
# Your password is super_secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment