Matz,
#include? used for range check, #member? was for set
membership. But since they have same functionality
in Enumerable, some claimed having different
behaviors in Range was confusing. I agreed.All we need is making up good names for each
functionality.
OK, I think I see why they were changed to be the same, but I really
don't understand the choice of functionality that was kept. For
everything except Ranges, #include? and #member? checks for set
membership. In Ranges, #include? and #member? don't check for set
membership, they check for interval coverage instead. This seems worse
than the original situation where at least #member? meant the same thing
everywhere.
One other side note on the current names: "include" and "member" are
really opposite ideas. A range includes a value, but a value is a
member of a range. Having them mean exactly the same thing might also
be confusing.
Anyway, could Range#include? and Range#member? be changed back to a
membership check and a new method be added to Range for interval
coverage, or would that break too much backwards compatibility? Several
names come to mind for the new method: #between? (my personal favorite),
#betwixt? (kind of silly, but could be fun), #cover?, #surround?,
#bound?, #inside?, #within?, #in_range?, #in_interval?, #in?
If the current behavior of the Range methods can't be changed, names
for membership checks (not including #member? - yuck!) could be:
#among?, #amid?, #amidst?, #component?, #constituent?, #part?, #has?,
#in?
What do you think?
- Warren Brown