Created
May 14, 2014 15:46
-
-
Save ifyouseewendy/bff7d7b71870363c7b7d to your computer and use it in GitHub Desktop.
get random result by `method_missing`
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 Roulette | |
def method_missing(name, *args) | |
person = name.to_s.capitalize | |
super unless %w(Wendi Larry Dapian).include? person | |
number = 0 | |
3.times do | |
number = rand(10) + 1 | |
puts "#{number}..." | |
end | |
"#{person} got a #{number}" | |
end | |
end | |
number_of = Roulette.new | |
number_of.wendi | |
# 5... | |
# 10... | |
# 2... | |
# => "Wendi got a 2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment