Created
July 25, 2014 16:14
-
-
Save joellusky/d40937f9f541dd2601f5 to your computer and use it in GitHub Desktop.
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
def add_two(number) | |
if number.respond_to? :+ | |
if number.respond_to? :push | |
number.push 2 | |
elsif number.class == String | |
number + "2" | |
else | |
number + 2 | |
end | |
else | |
puts "NOT A VALID ANSWER" | |
end | |
end | |
def test_add_two | |
puts add_two(1) | |
puts add_two(1.0) | |
puts add_two(nil) | |
puts add_two({}) | |
puts add_two([]) | |
puts add_two(false) | |
puts add_two("1") | |
end | |
test_add_two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment