Kedar Mhaswade wrote:

> Sorry if this is asked before and I could not find its answer. Take a
> look at the following:
> ------------------------------------------
> 1 #!/usr/bin/ruby
> 2 s="test"
> 3 puts s
> 4 s="surprising" if (1+1 != 2)
> 5 puts s
> ------------------------------------------
> which produces the output:
> test
> test
> 
> but I expected it to output:
> test
> nil
> 
> since I thought the expression in line number 5 ("surprising" if (1+1
> != 2)) should evaluate to nil and hence s should be assigned nil.
> 
> So, my question is:
> - Why?
> - What should I read to understand this better?
> 
> Thank you!
> -Kedar

This doesn't change because the string s is "test".  Since 1+1 is 2, it
will not change the value of s (thus it's still "test").  Only if it
were true would it result in "surprising".  It's doing exactly what it
should do.  The result of the conditional would be nil, but this is why
it's not changing it, and s remains the same value.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!