Skip to content

Instantly share code, notes, and snippets.

@huezoaa
Last active August 29, 2015 14:13
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 huezoaa/e15c2b3166f50a814ebc to your computer and use it in GitHub Desktop.
Save huezoaa/e15c2b3166f50a814ebc to your computer and use it in GitHub Desktop.
Add_two
# 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