Why does Rails titlecase add a space to a name?

前端 未结 10 1278
我在风中等你
我在风中等你 2021-02-05 10:28

Why does the titlecase mess up the name? I have:

John Mark McMillan

and it turns it into:

>> \"john mark McM         


        
10条回答
  •  轮回少年
    2021-02-05 10:45

    Hmm, that's odd.. but you could write a quick custom regex to avoid using that method.

    class String
        def custom_titlecase
            self.gsub(/\b\w/) { |w| w.upcase }
        end
    end
    
    "John Mark McMillan".custom_titlecase    # => "John Mark McMillan"
    

    Source

提交回复
热议问题