-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Add keyword_init option to Struct.new #5061
Add keyword_init option to Struct.new #5061
Conversation
I gave a shot to the implementation of this new feature and although all existing tests (and the new ones exercising this change) in I decided to test if inheritance work as expected and I wrote the following test to verify but I found out some assertions are failing: def test_struct_new_with_keyword_init_and_inheritance
klass = @Struct.new(:a, keyword_init: true)
klass2 = Class.new(klass)
assert_raise(ArgumentError) { klass2.new(1) } # broken, nothing is raised: => #<struct a=1>
assert_nothing_raised { klass2.new(a: 5) } # nothing is raised but is wrong as well: => #<struct a={:a=>5}>
o = klass2.new(a: 5) # wrong => #<struct a={:a=>5}>
assert_equal(5, o.a) # broken: o.a => {:a=>5}
end Where should I look to get this working? BTW, do you see worthwhile to contribute that extra test to MRI or ruby/spec? |
Thank you for the PR! Regarding your test:
|
@headius Thanks for the pointer, I just saw what's the problem with the inheritance in this case. I'll update the PR soon. |
10985df
to
dea2028
Compare
@headius The issue I pointed out in my previous comment is now fixed. I'll try to submit my extra test to ruby/spec later. |
throw getRuntime().newArgumentError("unknown keywords: " + unknownKeywords); | ||
} | ||
} | ||
|
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.
I realised I was reimplementing functionality already available in JRuby with these checks. I'll update this PR soon to address that.
dea2028
to
bfa648a
Compare
For more information, please see feature #11925.
bfa648a
to
6746380
Compare
Hi folks,
This is another feature targeting Ruby 2.5 [1]: Add keyword_init option to Struct.new (feature #11925).
Thanks for your review and feedback.