用gsub替换为大写字符

时间:2013-08-01 10:20:45

标签: ruby regex gsub

我有许多简单的字符串'som', 'man', 'pal'等 我如何制作元音字符upcase!,让元音正则表达式或数组输出如'sOm','pAl','mAn'?

1 个答案:

答案 0 :(得分:7)

"som".gsub(/[aeiou]/, &:upcase)
# => "sOm"

"som".tr("aeiou", "AEIOU")
# => "sOm"