[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Range as conditional expr

omirek10

7/10/2006 1:20:00 PM

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?

Regards

2 Answers

Steve

7/10/2006 4:11:00 PM

0

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?
>
> Regards

omirek10

7/11/2006 12:28:00 PM

0

Thanks Steve. I need to obtain 2nd edition indeed.

Regards