ruby - What is a def ... else ... end construct? -
ruby - What is a def ... else ... end construct? -
i have code:
def with_else puts 'we come in funny' if true puts "yes" 'return yes' end 'return what?' else puts 'no' 'return else -> no' end puts with_else and output this:
we come in funny yes no homecoming else -> no why don't error that? def/else/end mean?
http://rubyfiddle.com/riddles/8df07
this part of larger syntactical structure:
def foo # method stuff rescue # stuff if exception caught else # stuff if no exception caught ensure # run after rescue , else end but each section optional! can leave out rescue , ensure example.
ruby
Comments
Post a Comment