-
-
Save aguayma/ff5078feb8048cb590a2 to your computer and use it in GitHub Desktop.
Hey you can't do that here
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
# Add 2 to the number. | |
def add_two(number) | |
if number.respond_to? :+ | |
if number.respond_to? :push | |
number.push 2 | |
elsif number.respond_to? :squeeze | |
puts "Please enter a valid number!" | |
else | |
number + 2 | |
end | |
end | |
end | |
def test_add_two | |
p add_two(1) | |
p add_two(1.0) | |
p add_two(nil) | |
p add_two({}) | |
p add_two([]) | |
p add_two(false) | |
p add_two("") | |
end | |
test_add_two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment