之间有什么区别吗?
def some_method
some_instructions and return
end
和:
def some_method
return some_instructions
end
之间有什么区别吗?
def some_method
some_instructions and return
end
和:
def some_method
return some_instructions
end
是的,有:如果返回值为真,则第一个返回nil
,如果返回值为some_instructions
假,则some_instructions
返回some_instructions
。第二个总是返回的返回值some_instructions
。
有。
def some_method
some_instructions and return
end
返回nil
。更新:正如 Arie Shaw 指出的那样,Jorg 的回答是,如果some_instructions
为 false(或 nil),则该方法将返回 false(或 nil)并且不会运行return
def some_method
return some_instructions
end
返回由返回的值some_instructions