Skip to content

Instantly share code, notes, and snippets.

@domhnall
Created March 15, 2023 21:32
Show Gist options
  • Save domhnall/e744b886979cb46433dc85c8ebd64e28 to your computer and use it in GitHub Desktop.
Save domhnall/e744b886979cb46433dc85c8ebd64e28 to your computer and use it in GitHub Desktop.
Snippet demonstrating that there is no implicit return value from the ensure block in ruby
def no_ensure
:ok
end
def with_ensure
:ok
ensure
:ensure
end
def with_ensure_and_return
:ok
ensure
return :ensure
end
# Output
puts no_ensure # Returns :ok
puts with_ensure # Returns :ok
puts with_ensure_and_return # Returns :ensure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment