ruby-changes:64761
From: Adam <ko1@a...>
Date: Wed, 6 Jan 2021 08:35:04 +0900 (JST)
Subject: [ruby-changes:64761] e13f41e02d (master): [ruby/ostruct] Allow ostruct to return a value on super (#4028)
https://git.ruby-lang.org/ruby.git/commit/?id=e13f41e02d From e13f41e02df0d29fbde659b9e426862a8d433003 Mon Sep 17 00:00:00 2001 From: Adam Hess <HParker@g...> Date: Tue, 5 Jan 2021 15:34:45 -0800 Subject: [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@h...> diff --git a/lib/ostruct.rb b/lib/ostruct.rb index a5a5140..e7beac0 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -240,6 +240,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L240 end set_ostruct_member_value!(mname, args[0]) elsif len == 0 + @table[mid] else begin super diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 3ca98ee..443a20c 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -249,6 +249,14 @@ class TC_OpenStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L249 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) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/