бы после "-" шла заглавная буква
x = ["Allen Rick", "Bacon Don", "Bergman Jack", "Bice Stephanie", "Biggs Andy", "Bishop Dan", "Boebert Lauren", "Buck Ken", "Budd Ted", "Burchett Tim", "Carter Earl", "Cawthorn Madison", "Cloud Michael", "Davidson Warren", "Davis Rodney", "Desjarlais Scott", "Diaz-balart Mario", "Donalds Byron", "Duncan Jeff", "Dunn Neal", "Ellzey Jake", "Fischbach Michelle", "Franklin C.", "Garbarino Andrew", "Garcia Mike", "Gohmert Louie", "Gonzales Tony", "Good Bob", "Gosar Paul", "Graves Garret", "Griffith H.", "Grothman Glenn", "Guthrie Brett", "Harris Andy", "Harshbarger Diana", "Hern Kevin", "Herrell Yvette", "Hice Jody", "Higgins Clay", "Hill J.", "Hinson Ashley", "Jackson Ronny", "Jacobs Chris", "Johnson Bill", "Johnson Mike", "Joyce John", "Kelly Trent", "Kim Young", "Lesko Debbie", "Letlow Julia", "Malliotakis Nicole", "Mckinley David", "Meijer Peter", "Meuser Daniel", "Miller-meeks Mariannette", "Miller Carol", "Miller Mary", "Moolenaar John", "Mooney Alexander", "Moore Blake", "Murphy Gregory", "Nehls Troy", "Palazzo Steven", "Pence Greg", "Reschenthaler Guy", "Rice Tom", "Rodgers Cathy", "Rogers Mike", "Smith Christopher", "Smucker Lloyd", "Spartz Victoria", "Steube W.", "Tiffany Thomas", "Van Duyne Beth", "Walberg Tim", "Weber Randy", "Westerman Bruce", "Wittman Robert"]
пытаюсь решить, на выходе то же что и было
def co_(x)
if x.nil? || x.join == ""
return nil
elsif x.join.include?("-")
x.map do |e|
if e.include?("-")
e = e.split("-")
e.map { |b| b = b.titleize}
e = e.join("-")
end
end
puts x
return x
end
end
Вам нужно сделать перебор и заменить букву. Используйте map и gsub с позитивным просмотром назад. Что-то типа такого: arr.map { |str| str.gsub(/(?<=-)\w/) { |i| i.capitalize} }
Я вот так сделал, говнокод но работает x = ["123n-c123", "Name1 Name2", "Name3-name", "Name4", "Name Name"] def wordupper(array) y = [] for words in array do if words =~ /[-]/ to_get = words.split('') i = 0 b = [] for word in to_get do if word =~ /[-]/ next_chek = i + 1 element = to_get[next_chek] t = element.upcase tire = "-" b << tire b << t to_get.delete_at(i) else b << word end i += 1 end a = b.join('') y << a else y << words end end puts y end wordupper(x) ## 123n-C123 Name1 Name2 Name3-Name Name4 Name Name
Обсуждают сегодня