ruby-core

Mailing list archive

[#71931] [Ruby trunk - Feature #11786] [Open] [PATCH] micro-optimize case dispatch even harder — normalperson@...

Issue #11786 has been reported by Eric Wong.

9 messages 2015/12/08

[ruby-core:72034] [Ruby trunk - Bug #11802] Hash.new and {} have different behaviour

From: hanmac@...
Date: 2015-12-10 15:59:42 UTC
List: ruby-core #72034
Issue #11802 has been updated by Hans Mackowiak.


`p {}` is parsed as `p() { }`

you see it when you try:

~~~ruby
p { :key => "value"} #which does raise a Syntax Error
~~~

you need `()`

~~~ruby
p({ :key => "value"}) # => {:key=>"value"}
~~~ 

----------------------------------------
Bug #11802: Hash.new and {} have different behaviour
https://bugs.ruby-lang.org/issues/11802#change-55445

* Author: Marek Aufart
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
It looks that {} is not recognized as a variable sometimes.

irb(main):001:0> p Hash.new
{}
=> {}
irb(main):002:0> p {}
=> nil

Similar in rspec test:

expect(subject.something).to eq {} # fails on not given argument for eq
expect(subject.something).to eq({}) # works




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next