Skip to content

Instantly share code, notes, and snippets.

@drhuffman12
Created November 1, 2016 18:33
Show Gist options
  • Select an option

  • Save drhuffman12/fb0b2b72c6df8b8f9804a124b9a55b0d to your computer and use it in GitHub Desktop.

Select an option

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
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