From: pjb@... (Pascal J. Bourguignon) Date: 2009-01-10T09:54:35+09:00 Subject: Re: value of an expression? Kedar Mhaswade writes: > Sorry, I had a glimmer of hope but this script eclipsed it :( > confused.rb > ----------- > #!/usr/bin/ruby > > s="test" > puts s > s="surprising" if (1+1!=2) > puts s > s=("surprising" if (1+1!=2)) > puts s > ------------ > > Outputs: > test > test > nil > > so, to add to a newbie's confusion, a pair of parenthesis does the > expected. What did you expect? case 1: (s = "surprising") if ((1 + 1) != 2) won't assign unless (1+1)!=2 case 2: s = ("surprising" if ((1 + 1) != 2)) will assign the result of the parenthese, which will be "surprising" if ((1 + 1) != 2) (and nil otherwise). If you wanted not to do any assignment to s, then you should go back to case 1. -- __Pascal Bourguignon__