[ruby-core:77398] [Ruby trunk Bug#12758][Rejected] Error when passing Hash construction to function
From:
shyouhei@...
Date:
2016-09-26 10:15:53 UTC
List:
ruby-core #77398
Issue #12758 has been updated by Shyouhei Urabe.
Status changed from Open to Rejected
Let me reject this (a FAQ).
----------------------------------------
Bug #12758: Error when passing Hash construction to function
https://bugs.ruby-lang.org/issues/12758#change-60653
* Author: Jimi Damon
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
* Backport: 2.3: UNKNOWN
----------------------------------------
I apologize if this is a known issue but I couldn't find it in the search.
If you have a function that can take a Hash, it behaves correctly if you pass a variable that contains the Hash compared to when you pass in a Hash construction using braces {}.
Example
def foo(a)
puts a.class
puts a
end
> foo [1,2]
Array
[1, 2]
> a = { a:1 }
> foo a
Hash
{:a=>1}
# This breaks
> foo { a:1 }
SyntaxError: (irb):23: syntax error, unexpected ':', expecting '}'
foo {a:1}
^
but this works
> foo( {a:1} )
Hash
{:a=>1}
This is more of a bug related to consistent syntax of the language and it is something that is allowed in Groovy and Scala
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>