[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:
parent
3108ad7bf3
commit
e13f41e02d
Notes:
git
2021-01-06 08:35:22 +09:00
Merged-By: marcandre <github@marc-andre.ca>
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user