How to convert a string to lower or upper case in Ruby

后端 未结 11 963
梦如初夏
梦如初夏 2020-12-07 07:00

How do I take a string and convert it to lower or upper case in Ruby?

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 07:08

    In combination with try method, to support nil value:

    'string'.try(:upcase)
    'string'.try(:capitalize)
    'string'.try(:titleize)
    

提交回复
热议问题