Skip to content

Instantly share code, notes, and snippets.

@wbailey
Created December 22, 2010 20:17
Show Gist options
  • Save wbailey/752036 to your computer and use it in GitHub Desktop.
Save wbailey/752036 to your computer and use it in GitHub Desktop.
A trick using a closure for memoization
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