зеркало из https://github.com/github/ruby.git
[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:
Родитель
3108ad7bf3
Коммит
e13f41e02d
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче