From: Kedar Mhaswade Date: 2009-01-10T12:43:05+09:00 Subject: Re: value of an expression? Pascal J. Bourguignon wrote: > Kedar Mhaswade writes: >> 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. Tim and Pascal, I certainly appreciate your attempts to make me get it. I think I am close. The only weird thing is I was not sure whether "surprising" if (1+1 != 2) is an "expression" and if yes, what its value was. I thought that this expression is same as ("surprising" if (1+1 != 2)) and both should evaluate to the same value. Thus, whereas now I get that the value of ("surprising" if (1+1 != 2)) is nil, it is not clear to me if - "surprising" if (1+1 != 2) is an expression and evaluates to some/same value. Apologies if this is becoming rather lengthy. Regards, Kedar -- Posted via http://www.ruby-forum.com/.