Skip to content

Commit

Permalink
[ruby/ostruct] Fix class and method as attribute names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladislav Gallay authored and hsbt committed Mar 7, 2022
1 parent 1dd2d2c commit e1391bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ostruct.rb
Expand Up @@ -246,7 +246,7 @@ def new_ostruct_member!(name) # :nodoc:
if owner.class == ::Class
owner < ::OpenStruct
else
self.class.ancestors.any? do |mod|
self.class!.ancestors.any? do |mod|
return false if mod == ::OpenStruct
mod == owner
end
Expand Down
6 changes: 6 additions & 0 deletions test/ostruct/test_ostruct.rb
Expand Up @@ -406,4 +406,10 @@ def test_marshal
o2 = Marshal.load(Marshal.dump(o))
assert_equal o, o2
end

def test_class
os = OpenStruct.new(class: 'my-class', method: 'post')
assert_equal('my-class', os.class)
assert_equal(OpenStruct, os.class!)
end
end

0 comments on commit e1391bf

Please sign in to comment.