Last active
August 29, 2015 14:13
-
-
Save huezoaa/e15c2b3166f50a814ebc to your computer and use it in GitHub Desktop.
Add_two
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? :upcase | |
# Your entry is must be a String | |
number + "2" | |
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("1 and ") | |
end | |
test_add_two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment