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

refactor Range#include? for range value #4197

Merged
merged 1 commit into from
Dec 26, 2011

Conversation

nashby
Copy link
Contributor

@nashby nashby commented Dec 26, 2011

No description provided.

josevalim added a commit that referenced this pull request Dec 26, 2011
refactor Range#include? for range value
@josevalim josevalim merged commit 28b008b into rails:master Dec 26, 2011
operator = exclude_end? ? :< : :<=
end_value = value.exclude_end? ? last.succ : last
include_without_range?(value.first) && (value.last <=> end_value).send(operator, 0)
min <= value.min && max >= value.max
Copy link
Contributor

Choose a reason for hiding this comment

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

What about descending ranges, e.g. 3..1?

irb(main):002:0> (3..1).min
=> nil
irb(main):003:0> (3..1).max
=> nil

@nashby
Copy link
Contributor Author

nashby commented Dec 26, 2011

Actually, now it works pretty strange:

1.9.2p290 :006 > (3..1).include?(1..2)
 => false 
1.9.2p290 :007 > (1..3).include?(2..1)
 => true 

for plain include? method:

1.9.2p290 :008 > (3..1).include?(2)
 => false 

so, what's the best solution? Just check min && value.min are not nil?

@lest
Copy link
Contributor

lest commented Dec 26, 2011

I think it's good to return false in

(3..1).include?(1..2)

but I don't know what is the best in

(1..3).include?(2..1)

@josevalim could you share your thoughts?

@josevalim
Copy link
Contributor

Unsure. What did the previous implementation return?

@nashby
Copy link
Contributor Author

nashby commented Dec 26, 2011

it's above.

@josevalim
Copy link
Contributor

No idea then. /cc @fxn

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.

None yet

3 participants