Skip to content

Commit

Permalink
Allow ostruct to return a value on super (#4028)
Browse files Browse the repository at this point in the history
This fixes cases where you can super in something that inherits from OpenStruct

Co-authored-by: John Hawthorn <john@hawthorn.email>
  • Loading branch information
2 people authored and marcandre committed Jan 6, 2021
1 parent f2bc4ec commit 69cbbef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def freeze
end
set_ostruct_member_value!(mname, args[0])
elsif len == 0
@table[mid]
else
begin
super
Expand Down
8 changes: 8 additions & 0 deletions test/ostruct/test_ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ def test_overriden_private_methods
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)
Expand Down

0 comments on commit 69cbbef

Please sign in to comment.