[ruby/ostruct] Allow ostruct to return a value on super (#4028)

This fixes cases where you can super in something that inherits from OpenStruct

Co-authored-by: John Hawthorn <john@hawthorn.email>
This commit is contained in:
Adam Hess 2021-01-05 15:34:45 -08:00 committed by GitHub
parent 3108ad7bf3
commit e13f41e02d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2021-01-06 08:35:22 +09:00
Merged-By: marcandre <github@marc-andre.ca>
2 changed files with 9 additions and 0 deletions

View File

@ -240,6 +240,7 @@ class OpenStruct
end
set_ostruct_member_value!(mname, args[0])
elsif len == 0
@table[mid]
else
begin
super

View File

@ -249,6 +249,14 @@ class TC_OpenStruct < Test::Unit::TestCase
assert_equal(:bar, os.format)
end
def test_super
c = Class.new(OpenStruct) {
def foo; super; end
}
os = c.new(foo: :bar)
assert_equal(:bar, os.foo)
end
def test_overridden_public_methods
os = OpenStruct.new(method: :foo, class: :bar)
assert_equal(:foo, os.method)