Created
December 22, 2010 20:17
-
-
Save wbailey/752036 to your computer and use it in GitHub Desktop.
A trick using a closure for memoization
This file contains 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 github_user | |
@github_user ||= begin | |
github_user, shell_user = %x{git config --get github.user}.chomp, ENV['USER'].to_s | |
raise Exception, 'Unable to determine github user' if (github_user + shell_user).empty? | |
github_user.empty? ? shell_user : github_user | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment