Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ostruct to return a value on super #4028

Merged
merged 1 commit into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ostruct.rb
Expand Up @@ -240,6 +240,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
Expand Up @@ -249,6 +249,14 @@ def test_overridden_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