Last active
June 27, 2017 11:49
-
-
Save shivabhusal/f407dfd0d05912c0eae272d7a8569a76 to your computer and use it in GitHub Desktop.
Run this code in your machine and find the bug
This file contains 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 | |
3.times do | |
number = rand(10) + 1 | |
puts "#{number}..." | |
end | |
"#{person} got a #{number}" | |
end | |
end | |
# You can use the Roulette like this: | |
number_of = Roulette.new | |
puts number_of.bob | |
puts number_of.frank | |
# Expected output | |
# 5... | |
# 6... | |
# 10... | |
# Frank got a 10 | |
# 7... | |
# 4... | |
# 3... | |
# Bob got a 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the
number
variable doesn't exist out of the loop block.You should use instance variable
@number
or definenumber
before the loop block.