Why does the context (array constructor) make a difference with
respect to disambiguation?
I don’t think the context per se plays the role, but instead of
what the parser is trying to do.
You can compare this if you create a new array without []:
def f(i)
return i
end
Array.new(f 5) # => [nil, nil, nil, nil, nil]
This will work, so there is something inherently different for the use
of [].
I can’t off the top of my head name why [] is parsed differently but I
think there exists a reason why it is not possible, as otherwise it
would have been allowed by the lexer/parser or however it is called.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.