-
-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ruby 2.7] Add specs for pattern matching #751
Conversation
Great, thank you for starting those! |
0a4a73c
to
2998958
Compare
Yeah, you are right. TBH I'm concerned about readability because I use case {a: 1}
in String[a: 1]
ScratchPad << :foo
else
ScratchPad << :else
end
ScratchPad.recorded.should == [:else] but it could be done shorter with checking case expression result like case {a: 1}
in String[a: 1]
true
else
false
end.should == false What would you prefer? |
I would use the shorter second version, it could look like this with eval(<<~RUBY).should == false
case {a: 1}
in String[a: 1]
true
else
false
end
RUBY ( |
2998958
to
939d629
Compare
7abf1b8
to
9cfe5b8
Compare
There is only one failing spec (on MacOS) not relevant to the PR:
Actually there was another failing spec on Windows related to sockets. After re-running it passed but another spec, mentioned above, failed. So I would like to merge the PR as is but waiting for your approval. |
|
||
hash.deconstruct_keys([:a]).should == {a: 1, b: 2} | ||
hash.deconstruct_keys(0 ).should == {a: 1, b: 2} | ||
hash.deconstruct_keys('' ).should == {a: 1, b: 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if this is intended behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like so - https://github.com/ruby/ruby/blob/master/hash.c#L4591-L4595
Keys passed as argument are just a hint to optimize performance. Struct#deconstruct_keys
uses keys... Hash doesn't. At least for now. Hope it will be changed in the next release.
This is a great PR, thank you! Sorry for the transient failure, I'd guess it was a particularly slow run, maybe we should just bump the timeout. |
There is no official documentation yet so specs are based on: