How do I accept only letters in the entry in Ruby?

-2

Given a string, you have to take only the uppercase and lowercase letters. And on the output show the same. How can I achieve this?

    
asked by anonymous 14.08.2018 / 20:45

1 answer

1
class String
  def pega_maiusculas
    self.scan /\p{Upper}/
  end
  def pega_minusculas
    self.scan /\p{Lower}/
  end
end

str = "Teste TeStE tEsTe"
maiusculas = str.pega_maiusculas
minusculas = str.pega_minusculas

puts maiusculas
puts "\n"
puts minusculas
    
14.08.2018 / 20:51