I am working in Ruby and have found the need to have conditional return statements at the end of some/most of my methods.
Here is what I have:
# <ident-list> -> [ident] <ident-A>
def ident_list(keys)
id = nil
ident_a_node = nil
## method hidden
return IdentifierListNode.new(id, ident_a_node) unless id.nil?
return nil
end
Is there a better/cleaner way to go about this with multiple returns?
The last line before the
endcan be simplyThe last statement executed is the return value of the method. If
idis nil, the statement will evaluate as nil, and if not then the new IdentifierListNode instance will be returned.