Skip to content

Instantly share code, notes, and snippets.

@allolex
Created October 12, 2015 15:35
Show Gist options
  • Save allolex/f3cca8fd396852803c4d to your computer and use it in GitHub Desktop.
Save allolex/f3cca8fd396852803c4d to your computer and use it in GitHub Desktop.
def add_two number
return nil unless number.respond_to? :+
# if number.respond_to? :+
if number.respond_to? :concat
if number.respond_to? :push
number.push 2
else
number.concat "2"
end
else
number + 2
end
# end
end
def add_five number
# …
end
def test_add_two
p add_two(2) == 4
p add_two(1) == 3
p add_two(1.0) == 3.0
p add_two("a") == "a2"
p add_two([]) == [2]
p add_two([1]) == [1,2]
p add_two({}) == nil
p add_two(nil) == nil
p add_two(true) == nil
end
def test_add_five
# test with expectation for add_five
end
def test_all
test_add_two
test_add_five
end
test_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment