From: Florian Gilcher Date: 2008-04-19T21:11:06+09:00 Subject: Re: if behavior -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Apr 19, 2008, at 1:57 PM, Qwe Qwe wrote: > Hi, > i recently started to learn ruby as well as rails and came across a > problem. > such code: > [code] > if session[:login] > 10/0 > else > 11/0 > end if > [/code] > doesn't inform me about division by zero. Actually it seems that > none of > paths is evaluated. I don't get it. I've checked few tutorials, none > of > the said anything about possibility of such behavior. > -- > Posted via http://www.ruby-forum.com/. > Yes, because the code never gets evaluated. if-blocks are ended by "end" and not "end if". What you wrote can be interpreted as: ==== (if session[:login] 10/0 else 11/0 end) if ==== So: execute the if statement, if.... As there is no second condition on the second if, it is always false. So the code inside the paranthesis will never get executed. This is happening because ruby allows you to write a condition after a statement, e.g.: ==== do_weird_things if (true == ruby.is_driving_crazy?(you)) ==== Regards, Florian Gilcher -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkgJ4UsACgkQJA/zY0IIRZZzfQCgl55ikkAE3ysW88WM0w1Qf5TD zrcAnR+hGkdRXkQrLFbUqXLeNofIJtiD =ROnh -----END PGP SIGNATURE-----