Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ def new_ostruct_member!(name) # :nodoc:
private :new_ostruct_member!

private def is_method_protected!(name) # :nodoc:
if !respond_to?(name, true)
sc = singleton_class!
if !(sc.method_defined?(name) || sc.private_method_defined?(name))
false
elsif name.match?(/!$/)
true
else
owner = method!(name).owner
owner = sc.instance_method(name).owner
if owner.class == ::Class
owner < ::OpenStruct
else
Expand Down
6 changes: 6 additions & 0 deletions test/ostruct/test_ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,10 @@ def test_performance_warning
)
end
end
def test_initialize_with_respond_to_field
o = OpenStruct.new(respond_to?: false, next_field: 3)

assert_equal({respond_to?: false, next_field: 3}, o.to_h)
end

end