From 26e15bc1aad3eb9536389e833105fb59e99918c0 Mon Sep 17 00:00:00 2001 From: Ladislav Gallay Date: Tue, 18 Jan 2022 14:54:52 +0100 Subject: [PATCH] Fix class and method as attribute names --- lib/ostruct.rb | 2 +- test/ostruct/test_ostruct.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 4dccfc4..2b739be 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -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 diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 6487cc8..256db7a 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -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