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

ruby-changes:60117

From: Nobuyoshi <ko1@a...>
Date: Wed, 19 Feb 2020 16:15:55 +0900 (JST)
Subject: [ruby-changes:60117] f0b815dc67 (master): `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]

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

From f0b815dc670b61eba1daaa67a8613ac431d32b16 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 28 Nov 2019 12:18:17 +0900
Subject: `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]


diff --git a/NEWS.md b/NEWS.md
index 1d5bd6a..203fa08 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -34,6 +34,13 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS.md#L34
         * Hash#transform_keys now accepts a hash that maps keys to new
           keys.  [[Feature #16274]]
 
+* Symbol
+
+    * Modified method
+
+        * Symbol#to_proc now returns a lambda Proc.
+          [[Feature #16260]]
+
 ## Stdlib updates (outstanding ones only)
 
 * Net::HTTP
@@ -71,6 +78,7 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS.md#L78
 [Feature #8948]:  https://bugs.ruby-lang.org/issues/8948
 [Feature #15575]: https://bugs.ruby-lang.org/issues/15575
 [Feature #16131]: https://bugs.ruby-lang.org/issues/16131
+[Feature #16260]: https://bugs.ruby-lang.org/issues/16260
 [Feature #16274]: https://bugs.ruby-lang.org/issues/16274
 [Feature #16377]: https://bugs.ruby-lang.org/issues/16377
 [Feature #16555]: https://bugs.ruby-lang.org/issues/16555
diff --git a/proc.c b/proc.c
index 83ec61d..e0cba71 100644
--- a/proc.c
+++ b/proc.c
@@ -697,6 +697,7 @@ sym_proc_new(VALUE klass, VALUE sym) https://github.com/ruby/ruby/blob/trunk/proc.c#L697
     GetProcPtr(procval, proc);
 
     vm_block_type_set(&proc->block, block_type_symbol);
+    proc->is_lambda = TRUE;
     RB_OBJ_WRITE(procval, &proc->block.as.symbol, sym);
     return procval;
 }
diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb
index 8b9c839..7edd11b 100644
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ b/spec/ruby/core/proc/shared/to_s.rb
@@ -46,7 +46,7 @@ describe :proc_to_s, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/proc/shared/to_s.rb#L46
   describe "for a proc created with Symbol#to_proc" do
     it "returns a description including '(&:symbol)'" do
       proc = :foobar.to_proc
-      proc.send(@method).should =~ /^#<Proc:0x\h+\(&:foobar\)>$/
+      proc.send(@method).should.include?('(&:foobar)')
     end
 
     it "has a binary encoding" do
-- 
cgit v0.10.2


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

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