Skip to content

Instantly share code, notes, and snippets.

@joellusky
Created July 25, 2014 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joellusky/d40937f9f541dd2601f5 to your computer and use it in GitHub Desktop.
Save joellusky/d40937f9f541dd2601f5 to your computer and use it in GitHub Desktop.
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