On Wed, May 30, 2001 at 04:11:24PM +0900, Benoit Cerrina wrote:
> Hi,

Hi!

> maybe you would find
> return result = getValue if result
> clearer?

If it works, I would. But does that "result = getValue" part get
evaluated before "if part". Version 1.6.4 of Ruby does not think
so. Or atleast following testcode does not visit those "getValue"
methods at all.

| #!/usr/local/bin/ruby
| 
| class Iftest
|   def returnTrue
|     puts ' -helper- Inside returnTrue'
|     true
|   end
|   def returnFalse
|     puts ' -helper- Inside returnFalse'
|     false
|   end
|   def returnNil
|     puts ' -helper- Inside returnNil'
|     nil
|   end
| 
|   def testTrue
|     puts 'Inside testTrue'
|     return result = returnTrue if result
|     puts 'You should not see this!'
|   end
| 
|   def testFalse
|     puts 'Inside testFalse'
|     return result = returnFalse if result
|     puts 'You should see this!'
|   end
| 
|   def testNil
|     puts 'Inside testNil'
|     return result = returnNil if result
|     puts 'You should see this!'
|   end
| 
|   def doTests
|     testTrue
|     testFalse
|     testNil
|   end
| end
| 
| test = Iftest.new
| test.doTests

My output is only:

| lanfear 10:39:49 jmp:~/data/ruby$ ruby iftest.rb 
| Inside testTrue
| You should not see this!
| Inside testFalse
| You should see this!
| Inside testNil
| You should see this!
| lanfear 10:42:13 jmp:~/data/ruby$ 

-Jippo

-- 
 __________________________________________________________________
[   pub 1024/951AFAF5 1995/12/12   Juha Pohjalainen <jmp / iki.fi>   ]
[   fingerprint 41 56 7F F9 8E EC 16 35  BB 42 EF A7 DF 19 FA 31   ]
[__ http://www.iki.fi/jmp/ ________________ GSM +358 40 570 1179 __]