Where is Ruby's string literal juxtaposition feature officially documented?

后端 未结 4 1624
小鲜肉
小鲜肉 2020-11-28 14:52

I recently realized that if you juxtapose a sequence of Ruby string literals (e.g. \'a\' \"b\" \'c\'), it\'s equivalent to the concatenation of those string lit

4条回答
  •  春和景丽
    2020-11-28 15:23

    There is a reference in The Ruby Programming Language, page 47.

    It looks like it is deliberately in the parser, for situations where you want to split up string literals in code, but don't want to pay the price of concatenating them (and creating 3 or more strings). Long strings with no line breaks, and without requiring line-length busting code, are a good example

    text = "This is a long example message without line breaks. " \
        "If it were not for this handy syntax, " \
        "I would need to concatenate many strings, " \
        "or find some other work-around"
    

提交回复
热议问题