[前][次][番号順一覧][スレッド一覧]

ruby-changes:71337

From: Ladislav <ko1@a...>
Date: Mon, 7 Mar 2022 20:09:11 +0900 (JST)
Subject: [ruby-changes:71337] e1391bf96f (master): [ruby/ostruct] Fix class and method as attribute names

https://git.ruby-lang.org/ruby.git/commit/?id=e1391bf96f

From e1391bf96f03143387c500a168adb6fc9fc242c6 Mon Sep 17 00:00:00 2001
From: Ladislav Gallay <ladislav.gallay@l...>
Date: Tue, 18 Jan 2022 14:54:52 +0100
Subject: [ruby/ostruct] Fix class and method as attribute names

https://github.com/ruby/ostruct/commit/7258535073
---
 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 4dccfc4c63..2b739beed7 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -246,7 +246,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L246
       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 https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L406
     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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]