P
Patrick Toomey
Hello all,
I am new to Ruby and am toying around with the language to get a
feel for the expression ubiquity in ruby. Anyway, explain to me the
following. The below bits of code have no real relevance; they are
merely illustrative of my question. The first declaration works as
expected; the return value is 9. The second declaration doesn't run
at all. I get a "void value expression" error. Is the runtime
looking into my if statement, realizing that there is no ability for
x to get set and failing? Obviously the code is ridiculous, but it
seems odd to me that it would not even run. Why does the interpreter
care that x will never get set if the function will return cleanly
none the less?
def foo()
x = 0
x = if 3 > 4
8
else
9
end
return x
end
def foo()
x = 0
x = if 3 > 4
return 8
else
return 9
end
return x
end
I am new to Ruby and am toying around with the language to get a
feel for the expression ubiquity in ruby. Anyway, explain to me the
following. The below bits of code have no real relevance; they are
merely illustrative of my question. The first declaration works as
expected; the return value is 9. The second declaration doesn't run
at all. I get a "void value expression" error. Is the runtime
looking into my if statement, realizing that there is no ability for
x to get set and failing? Obviously the code is ridiculous, but it
seems odd to me that it would not even run. Why does the interpreter
care that x will never get set if the function will return cleanly
none the less?
def foo()
x = 0
x = if 3 > 4
8
else
9
end
return x
end
def foo()
x = 0
x = if 3 > 4
return 8
else
return 9
end
return x
end