[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 коммит произвёл GitHub
Родитель 3108ad7bf3
Коммит e13f41e02d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

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

Просмотреть файл

@ -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)