Skip to content

Instantly share code, notes, and snippets.

@ifyouseewendy
Created May 14, 2014 15:46
Show Gist options
  • Save ifyouseewendy/bff7d7b71870363c7b7d to your computer and use it in GitHub Desktop.
Save ifyouseewendy/bff7d7b71870363c7b7d to your computer and use it in GitHub Desktop.
get random result by `method_missing`
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