Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 创建一个titleize方法,该方法不包括;“小词”;。_Ruby - Fatal编程技术网

Ruby 创建一个titleize方法,该方法不包括;“小词”;。

Ruby 创建一个titleize方法,该方法不包括;“小词”;。,ruby,Ruby,我正在制作一种方法来大写我的输入,除了a、an和…等词 def titleize(string_to_titleize) string_to_titleize.split(' ').map { |words| words.capitalize }.join(' ') end 我知道做这件事有很多好处。我不知道怎么用手做这件事。我假设创建一个不大写的单词列表。然后,有人把他们排除在外 复制品?这很有帮助。谢谢你的帮助。 arr = ['a', 'an', 'the'] str ="Thi

我正在制作一种方法来大写我的输入,除了a、an和…等词

def titleize(string_to_titleize)
    string_to_titleize.split(' ').map { |words| words.capitalize }.join(' ')
end

我知道做这件事有很多好处。我不知道怎么用手做这件事。我假设创建一个不大写的单词列表。然后,有人把他们排除在外

复制品?这很有帮助。谢谢你的帮助。
arr = ['a', 'an', 'the']
str ="This is a salil gaikwad working as an engineer"
str.gsub(/\w+/) {|match| arr.include?(match) ? match : match.capitalize} 
#Gives o/p :- This Is a Salil Gaikwad Working As an Engineer