Created
March 15, 2023 21:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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