A
Ammar Ali
Hello,
Is there a built-in method for identifying character types a la
ctype() in C? I would like to avoid requiring a gem dependency.
I'm considering the following approach, if nothing exists, but it
seems like overkill to me.
def ctype(c)
case c
when /[[:alnum:]]/; :alnum
when /[[:alpha:]]/; :alpha
# etc...
end
end
def alnum?(c); ctype(c) == :alnum end
def alpha?(c); ctype(c) == :alpha end
# etc...
Also, it requires some 1.8 vs 1.9 special cases for 'ascii' and
'word', if not more.
Regards,
Ammar
Is there a built-in method for identifying character types a la
ctype() in C? I would like to avoid requiring a gem dependency.
I'm considering the following approach, if nothing exists, but it
seems like overkill to me.
def ctype(c)
case c
when /[[:alnum:]]/; :alnum
when /[[:alpha:]]/; :alpha
# etc...
end
end
def alnum?(c); ctype(c) == :alnum end
def alpha?(c); ctype(c) == :alpha end
# etc...
Also, it requires some 1.8 vs 1.9 special cases for 'ascii' and
'word', if not more.
Regards,
Ammar