Skip to content
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
feature/check-type-at-init
Mar 5, 2020
Merged

Add a type check on input.#6
Quentin Wentzler (Quiwin) merged 3 commits intomasterfrom
feature/check-type-at-init

Conversation

@Quiwin
Copy link
Copy Markdown
Contributor

Raise a TypeError if one of the position input is not a Numeric.

Raise a TypeError if one of the position input is not a Numeric.
Comment thread lib/loc/location.rb Outdated
attr_reader :lat, :lng

def initialize(lat, lng)
raise TypeError unless lat.is_a?(Numeric) && lng.is_a?(Numeric)
Copy link
Copy Markdown
Contributor

@BuonOmo Ulysse Buonomo (BuonOmo) Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@BuonOmo Ulysse Buonomo (BuonOmo) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread spec/loc/location_spec.rb Outdated
Co-Authored-By: Ulysse Buonomo <[email protected]>
@Quiwin Quentin Wentzler (Quiwin) merged commit c52f042 into master Mar 5, 2020
@ccyrille
Copy link
Copy Markdown
Contributor

@BuonOmo Ulysse Buonomo (BuonOmo) deleted the feature/check-type-at-init branch March 10, 2020 16:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants