0

Array with more than one string separated with space produces array with one concatenated string. IMHO, it should raise syntax error. Is this behavior correct?

["1" "2" "3"]
#=> ["123"]

1 Answer 1

4

This has nothing to do with array. It is a feature of string literal. If you write string literals in quotes next to each other, it represents the string that is given by the concatenation.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes: "1" "2" "3" => "123"
Got it. Is there any reason behind this?
I think the rationale goes back to C where you have the same feature. Yet, you cannot to something like "error in " __FILE__ ":" __LINE__ which is valid in C.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.