How about this?

def test(s)
  return ['1',''] if !s.is_a?(String) || s.empty?
  case s
  when /^([^\W_]+)/
  ['a', $1]
  when /^(\s+)/
  ['s', $1]
  when /^([[:cntrl:]]+)/
  ['c', $1]
  when /^([[:punct:]_]+)/
  ['p', $1]
  when /^([^\w\s[:cntrl:][:punct:]]+)/
  ['r', $1]
  end
end

-- 
Posted via http://www.ruby-forum.com/.