I'm ashamed to ask this, because it seems like it ought to be obvious, but how does one tell whether a given character in a string is upper or lowercase in Ruby? I see no obvious canned solution in the String
class.
I've resorted to the following, which does not consider non-ASCII codes:
def is_lower?(c)
c >= 'a' && c <= 'z'
end
def is_upper?(c)
! is_lower(c)
end
Something else I've considered is:
def is_lower?(c)
c != c.upcase
end
Is there something more idiomatic for this?
question from:
https://stackoverflow.com/questions/12713251/ruby-how-to-tell-if-character-is-upper-lowercase 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…