From: Glen Holcomb Date: 2010-02-19T05:02:53+09:00 Subject: Re: Ruby conditionals subtlety? --0003255592b609dc57047fe5735b Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On Thu, Feb 18, 2010 at 12:49 PM, Farhad Farzaneh wrote: > Hi, > > Anyone know why thse two forms of "unless" behave differently? > > > irb > irb(main):001:0> foo =3D true unless defined?(foo) > =3D> nil > irb(main):002:0> unless defined?(fooo) ; fooo =3D true ; end > =3D> true > > thx > -- > Posted via http://www.ruby-forum.com/. > > From playing around it doesn't look like unless is "behaving differently" Ruby has created a label for foo since it thinks it is going to be assignin= g it something (dynamic language) For example >> foo =3D true unless defined?(foo) =3D> nil >> unless defined?(fooo); fooo =3D true; end =3D> true >> foo =3D> nil >> fooo =3D> true >> foo =3D true unless defined?(foom) =3D> true >> foo =3D> true Basically it looks like foo appears to exist but it doesn't really exist ye= t so the first unless "acts" oddly. This is very interesting though. Perhap= s someone who knows what they are talking about can tell us why it appears to behave this way. --=20 "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can=92t hear a word you=92re saying." -Greg Graffin (Bad Religion) --0003255592b609dc57047fe5735b--