From: Alex Young Date: 2007-11-16T07:19:55+09:00 Subject: Re: (1..5) === 3 > true 3 === (1..5) > false Phrogz wrote: > On Nov 15, 2:56 pm, Michael Chow wrote: >> I know it's a method, but why doesn't Fixnum's === work properly with >> ranges? >> >> That should be the expected behavior, the expression is just as true one >> way as it is the other. > > What do you think "===" means? Hint: it's not the same as "==", or > "<<". And it doesn't mean "is equals to". Obviously (1..5) does not > equal 3. > > The #=== method is called in case statements, and it is up to each > class to define something reasonable. > > case 3 > when 1..5 > puts "(1..5) === 3 means 3 is inside the range." > when Integer > puts "Integer === 3 means that 3 is a sort of Integer" > end > Mentally, I parse "===" as "contains". That requires a little mental judo for RegExps, but that's a good thing :-) -- Alex