Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimise errors when using includes & excludes #11

Merged
merged 4 commits into from
May 11, 2016

Conversation

fran-worley
Copy link
Contributor

If includes is called on an input that supports the method then call
it, otherwise return false.

If we encounter a type error (e.g. String.include?(Integer) ) then also
return false.

Due to the enhanced complexity of the predicate lets make excludes?
simply be its opposite.

Fixes #10

If includes is called on an input that supports the method then call
it, otherwise return false.

If we encounter a type error (e.g. String.include?(Integer) ) then also
return false.

Due to the enhanced complexity of the predicate lets make excludes?
simply be its opposite.
input.include?(value)
begin
case input
when String, Range, Array, Hash then input.include?(value)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could just check if respond_to?(:include?) instead of listing these types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds nicer. Also makes it more flexible with custom classes.
I also really hate rescuing the type error but if couldn't think of a better way...

@jodosha
Copy link
Member

jodosha commented May 11, 2016

@fran-worley 👍

@fran-worley fran-worley merged commit a0cb3c4 into master May 11, 2016
@fran-worley fran-worley deleted the handle-includes-errors branch May 11, 2016 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants