Created
November 1, 2016 18:33
-
-
Save drhuffman12/fb0b2b72c6df8b8f9804a124b9a55b0d to your computer and use it in GitHub Desktop.
Snippet for printing ENV key-value pairs, w/ keys right-aligned and values left-aligned
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
| puts | |
| longest_key = ENV.keys.max_by(&:length) | |
| key_formatter = '%' + "#{longest_key.length}" + 's' | |
| puts "longest_key: '#{longest_key}'" | |
| puts "key_formatter: '#{key_formatter}'" | |
| puts "ENV:" | |
| puts | |
| ENV.each_pair do |k,v| | |
| puts "#{key_formatter % k}: #{v}" | |
| end | |
| puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment