From: "David A. Black" Date: 2005-11-29T01:07:05+09:00 Subject: Re: [BUG] string range membership Hi -- On Tue, 29 Nov 2005, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [BUG] string range membership" > on Tue, 29 Nov 2005 00:16:49 +0900, "Warren Brown" writes: > > | 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. > > I don't remember exactly but it's for the sake of performance. I've > thinking about this issue for last few days, and it could be made > better by treating numbers specially, just like we did for min and max > in Range. I think that as long as ranges have all of this array/set behavior -- as long as range and range.to_a share so much functionality -- ranges will always feel like two different objects. The whole idea of "membership" in a range has always seemed a little strange to me. I guess I think of ranges as very different from arrays and sets. > | 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? > > Thank you for the candidates. I'd like to hear opinion from others > (especially from English speakers). (0..5).to_a.include?(n) :-) But seriously.... If it's a method of Range, then it has to be from the range perspective, not the perspective of the argument. #encompass? comes to mind. There was an interesting discussion on IRC about how to check for complete inclusion of one range in another. #encompass? could, ummm, encompass that: (0..5).encompass?(4) # true (0..5).encompass?(5.1) # false (0..5).encompass?(1..2) # true (1..2).encompass?(0..5) # false etc. David -- David A. Black dblack@wobblini.net