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

ruby-changes:71497

From: Marc-Andr=C3=A9 <ko1@a...>
Date: Thu, 24 Mar 2022 21:37:33 +0900 (JST)
Subject: [ruby-changes:71497] ad5754162b (master): [ruby/ostruct] Avoid aliasing `block_given?` for JRuby [Fixes #40]

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

From ad5754162bddfd0ce2f11bd7fc7fce90ba6bf7ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lafortune?= <github@m...>
Date: Sat, 29 Jan 2022 18:13:45 -0500
Subject: [ruby/ostruct] Avoid aliasing `block_given?` for JRuby [Fixes #40]

https://github.com/ruby/ostruct/commit/14d04ff694
---
 lib/ostruct.rb | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 8be8704135..258ae436e0 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -356,14 +356,14 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L356
   #
   #   person.delete_field('number') { 8675_309 } # => 8675309
   #
-  def delete_field(name)
+  def delete_field(name, &block)
     sym = name.to_sym
     begin
       singleton_class.remove_method(sym, "#{sym}=")
     rescue NameError
     end
     @table.delete(sym) do
-      return yield if block_given!
+      return yield if block
       raise! NameError.new("no field `#{sym}' in #{self}", sym)
     end
   end
@@ -467,6 +467,11 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L467
   end
   # Other builtin private methods we use:
   alias_method :raise!, :raise
-  alias_method :block_given!, :block_given?
-  private :raise!, :block_given!
+  private :raise!
+
+  # See https://github.com/ruby/ostruct/issues/40
+  if RUBY_ENGINE != 'jruby'
+    alias_method :block_given!, :block_given?
+    private :block_given!
+  end
 end
-- 
cgit v1.2.1


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

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