Skip to content

Instantly share code, notes, and snippets.

@andyweiss1982
Created July 24, 2014 20:22
Show Gist options
  • Save andyweiss1982/8e21afe240be70f4923d to your computer and use it in GitHub Desktop.
Save andyweiss1982/8e21afe240be70f4923d to your computer and use it in GitHub Desktop.
TDD Strings
# Add 2 to the number.
def add_two(number)
if number.respond_to? :+
if number.respond_to? :push
number.push 2
elsif number.is_a?(String)
number.to_f + 2
else
number + 2
end
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("")
end
test_add_two
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment