I am reading "Programming Ruby" [a.k.a. Pickaxe]
and I found example
···
---
while gets
print if /a/ .. /e/
end
---
but one does not work. However, after changing it to:
----
while gets
print if (/a/=~$_) .. (/e/=~$_)
end
---
it works.
But, what is the problem with the first version?
In the Second Edition of the Pickaxe, on page 68 it says:
In older versions of Ruby, bare ranges could be used as
conditions in if, while, and similar statements. You
could, for example, have written the previous code
fragment as
while gets
print if /start/../end/
end
This is no longer supported. Unfortunately, no error is
raised; the test will simply succeed each time.
Hope this answers your question.
Cheers
omirek10@poczta.onet.pl wrote:
···
Hi,
I am reading "Programming Ruby" [a.k.a. Pickaxe]
and I found example
---
while gets
print if /a/ .. /e/
end
---
but one does not work. However, after changing it to:
----
while gets
print if (/a/=~$_) .. (/e/=~$_)
end
---
it works.
But, what is the problem with the first version?