Actions
Bug #10870
closedHash Literal Declined As First Argument
Bug #10870:
Hash Literal Declined As First Argument
Description
Hi,
When a hash literal is passed as first argument to a method, Ruby throws a syntax error.
Example code:
def foo *args
p args
end
foo 'Hello'
foo 123
foo ['Hello', 123]
foo {:hello => 123} # Syntax Error: Unexpected => Expecting }
However, shifting hash literal over to second place, somehow makes it all legal.
Cheers.
Updated by Anonymous over 11 years ago
foo {} without parentheses is equivalent to foo() {}, (i.e. passing a block to foo) not foo({}).
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Updated by NorthernLights (Imran "") over 11 years ago
Thanks.
Actions