是否可以在红宝石中打印按时间顺序排列的字符串?比如excel A - Z
的标题,然后是AA, AB, AC
。红宝石有可能吗?谢谢!
答案 0 :(得分:0)
string = 'A'
99.times { puts string.succ! }
答案 1 :(得分:-2)
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
[1, 2, 3].map(&:alph) # => ["A", "B", "C"]
[26, 27, 28].map(&:alph) # => ["Z", "AA", "AB"]