String concatenation in Ruby

前端 未结 16 1185
青春惊慌失措
青春惊慌失措 2020-11-28 01:28

I am looking for a more elegant way of concatenating strings in Ruby.

I have the following line:

source = \"#{ROOT_DIR}/\" << project <<          


        
16条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 01:43

    You may use + or << operator, but in ruby .concat function is the most preferable one, as it is much faster than other operators. You can use it like.

    source = "#{ROOT_DIR}/".concat(project.concat("/App.config"))
    

提交回复
热议问题