Skip to content

Instantly share code, notes, and snippets.

@wbotelhos
Created February 12, 2021 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbotelhos/3aaff949c534782e2296bdbb31b67444 to your computer and use it in GitHub Desktop.
Save wbotelhos/3aaff949c534782e2296bdbb31b67444 to your computer and use it in GitHub Desktop.
Country Code to Emoji Flag
def country_code_to_flag(country_code)
code = country_code.to_s.upcase
return unless code =~ /\A[A-Z]{2}\z/
code.codepoints.map { |codepoint| (codepoint + 127_397).chr(Encoding::UTF_8) }.join
end
country_code_to_flag("BR")
# => "🇧🇷"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment