如何从列索引26获取字符序列,例如
"AA"
?index_hash = Hash.new {|hash,key| hash[key] = hash[key - 1].next }.merge({0 => "A"})
index_hash[26] #=> "AA"
class Numeric
Alph = ("A".."Z").to_a
def alph
s, q = "", self
(q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero?
s
end
end
(26+1).alph #=> "AA"
c = "A"
26.times { c = c.next }
c # => "AA"