From: Yasushi Shoji Date: 2000-09-26T12:50:17+09:00 Subject: [ruby-talk:5126] Re: Types and === From: "Hal E. Fulton" Subject: [ruby-talk:5122] Re: Types and === Date: Tue, 26 Sep 2000 11:47:49 +0900 > But to ask the question, "Which of these strings matches this pattern?" I > cannot > do this: > > case /pattern/ > when str1 > stmt1 > when str2 > stmt2 > ... > end you *can* do this, sort of, using case. but, IMHO, i don't know i'd use it. IMHO, a problem usually solved by using case statement itself is not commutative? usually, we want string to match one regex and do the statement assosiated to, but don't we want to know all of the string that mutchs given regex? in that case, case is not well suited. use if. -- yashi class String alias_method '_===', '===' def ===(other) case other when Regexp other === self else _===(other) end end end case /[ab]o/ when 'abc' p 1 when 'abo' p 2 when 'ao' p 3 end