1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/ostruct] Fix class and method as attribute names

https://github.com/ruby/ostruct/commit/7258535073
This commit is contained in:
Ladislav Gallay 2022-01-18 14:54:52 +01:00 committed by Hiroshi SHIBATA
parent 1dd2d2ce48
commit e1391bf96f
2 changed files with 7 additions and 1 deletions

View file

@ -246,7 +246,7 @@ class OpenStruct
if owner.class == ::Class if owner.class == ::Class
owner < ::OpenStruct owner < ::OpenStruct
else else
self.class.ancestors.any? do |mod| self.class!.ancestors.any? do |mod|
return false if mod == ::OpenStruct return false if mod == ::OpenStruct
mod == owner mod == owner
end end

View file

@ -406,4 +406,10 @@ class TC_OpenStruct < Test::Unit::TestCase
o2 = Marshal.load(Marshal.dump(o)) o2 = Marshal.load(Marshal.dump(o))
assert_equal o, o2 assert_equal o, o2
end 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 end