String concatenation in Ruby

前端 未结 16 1173
青春惊慌失措
青春惊慌失措 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:49

    Concatenation you say? How about #concat method then?

    a = 'foo'
    a.object_id #=> some number
    a.concat 'bar' #=> foobar
    a.object_id #=> same as before -- string a remains the same object
    

    In all fairness, concat is aliased as <<.

提交回复
热议问题