Skip to content

Instantly share code, notes, and snippets.

@aguayma
Created January 15, 2015 22:57
Show Gist options
  • Save aguayma/ff5078feb8048cb590a2 to your computer and use it in GitHub Desktop.
Save aguayma/ff5078feb8048cb590a2 to your computer and use it in GitHub Desktop.
Hey you can't do that here
# 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