How to generate Excel column symbols in Ruby - Cool one-liner #1
Public
05 Oct 11:29

How to generate Excel column symbols in Ruby

('A'..'Z').to_a.unshift(nil).product(('A'..'Z').to_a).map { |arr| arr.compact.join }

If you would like to keep it as a CONSTANT it should be frozen

EXCEL_COLUMNS =
  ('A'..'Z').to_a.unshift(nil).product(('A'..'Z').to_a)
    .map { |arr| arr.compact.join }
    .map(&:freeze).freeze

Comments

Empty! You must sign in to add comments.