Ben Giddings wrote:
> Sean O'Dell wrote:
>> Try: if (3..5) === x
>
> That'll probably work... but I'm curious to know if Oliver Dain's
> method
> is supposed to work:
>
> if (x==3)..(x==5)
>
> and
>
> if (x==3)...(x==5)
>
> I'm surprised that they work at all, and I'm curious if the fact
> they work in some way is a fluke, or if it was a conscious decision
> to try to
> let them work like that. I'd expect a syntax error, but then again,
> ranges as objects confuse me. :)
>
> Ben
Its my understanding that its not a fluke but a design decision. The
main reason for doing it, I think, is for regex's. It allows you to
say things like:
while gets
print if /foo/../bar/
end
e.g. print all lines between foo and bar. While Sean's solution works
for numbers it doesn't work for regular expressions and that was my
application of interest (I gave a numerical example because it was
easier to understand).