Skip to content

Instantly share code, notes, and snippets.

@drusepth
Created May 24, 2017 21:08
Show Gist options
  • Select an option

  • Save drusepth/1972c40fd030ce3ef06e4e4dc9b22eaa to your computer and use it in GitHub Desktop.

Select an option

Save drusepth/1972c40fd030ce3ef06e4e4dc9b22eaa to your computer and use it in GitHub Desktop.
# Standard function
def divide param_x, param_y
return Infinity if param_y.zero?
param_x.to_f / param_y.to_f
end
# Doable implementation with tests block in-function
def divide_with_tests param_x, param_y
return Infinity if param_y.zero?
param_x / param_y.to_f
tests do
assert self(0, 3) == 0
assert self(6, 3) == 2
assert self(3, 0) == Infinity
end
end
# Ideal implementation with tests in a separate block than method code
def divide_with_tests param_x, param_y
return Infinity if param_y.zero?
param_x / param_y.to_f
tests
assert self(0, 3) == 0
assert self(6, 3) == 2
assert self(3, 0) == Infinity
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment