In Ruby my function func returns nil if myfunction1 returns a non nil value. I would somehow expect that func returns the value of rc. In other words it gets the value of the assignment even if it not executed:
def func
rc = myfunction1
rc = myfunction2 if rc.nil?
end
If I enhance func to this then func works like I expect:
def func
rc = myfunction1
rc = myfunction2 if rc.nil?
rc
end
Here is simplified version to try it yourself:
def func
rc = 3
rc = myfunction2 if rc.nil? # returns nil but rc has value 3
end
Is there is specific reason for this behaviour?