Why does ruby ​​require brackets here?

When i try to do

assert_equal { dry: true }, res

I get

syntax error, unexpected ':', expecting '}'

        assert_equal { dry: true }, res

but

assert_equal({ dry: true }, res)

works great. Why is the first form not enough for a ruby ​​to understand what I mean? Or, to be more precise, what does Ruby think I'm trying to do?

+4
source share
1 answer

In the first example, braces are interpreted as delimiting a block. Since dry: trueit is not a legal expression, you get SyntaxError.

+3
source

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


All Articles