Strict string behavior in Ruby

So, I played Ruby and noticed that it "a""b"returns "ab". If it were very strange and useless, I was wondering what this is called, and if it has a purpose. I would appreciate any answers. Thank!

0
source share
2 answers

This is called "string literal concatenation" , and it is common in many languages. More specifically, adjacent string literals that are not shared by any other operators are automatically concatenated. They can be considered only one string literal.

This exists in C, C ++, Python, and Ruby, to name a few.

, , , . -, Python :

hdr = struct.Struct('<'
    '8s'        # 0x00  Magic value
    'I'         # 0x08  Offset
    'I'         # 0x0C  Length
    'H'         # 0x10  Type
    'H'         # 0x12  Flags
)               # 0x14  (Total)

, , , .

+5

, << +.

0

Source: https://habr.com/ru/post/1570397/


All Articles