summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav Gallay <ladislav.gallay@lentil.sk>2022-01-18 14:54:52 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-03-07 20:08:22 +0900
commite1391bf96f03143387c500a168adb6fc9fc242c6 (patch)
treeb4fbbe791e892d4f039396511ec159b0538860ab
parent1dd2d2ce48d7ed0e16beb42ac923ccd069701958 (diff)
[ruby/ostruct] Fix class and method as attribute names
https://github.com/ruby/ostruct/commit/7258535073
-rw-r--r--lib/ostruct.rb2
-rw-r--r--test/ostruct/test_ostruct.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 4dccfc4c63..2b739beed7 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -246,7 +246,7 @@ class OpenStruct
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 6487cc831c..256db7a0c7 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -406,4 +406,10 @@ class TC_OpenStruct < Test::Unit::TestCase
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