This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Add a type check on input.#6
Merged
Quentin Wentzler (Quiwin) merged 3 commits intomasterfrom Mar 5, 2020
Merged
Conversation
Raise a TypeError if one of the position input is not a Numeric.
Ulysse Buonomo (BuonOmo)
suggested changes
Mar 5, 2020
| attr_reader :lat, :lng | ||
|
|
||
| def initialize(lat, lng) | ||
| raise TypeError unless lat.is_a?(Numeric) && lng.is_a?(Numeric) |
Contributor
There was a problem hiding this comment.
Could you raise a more precise error?
Ruby usually goes with:
TypeError (wrong argument type Float (expected String))
Here we could even afford:
lat should be a Numeric
couldn't we?
And why not use Float(). It coerces in a strict manner (1a raises but 1 gives 1.0). Although it would accept strings, so maybe not. What is your opinion on this one?
Contributor
Author
There was a problem hiding this comment.
You are right, it should be a custom message.
For Float() I am not sure there is a valid case where geopositions could be string.
Ulysse Buonomo (BuonOmo)
approved these changes
Mar 5, 2020
Co-Authored-By: Ulysse Buonomo <[email protected]>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Raise a TypeError if one of the position input is not a Numeric.