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

ruby-changes:43457

From: nobu <ko1@a...>
Date: Wed, 29 Jun 2016 08:46:01 +0900 (JST)
Subject: [ruby-changes:43457] nobu:r55531 (trunk): Passed block symbol to proc

nobu	2016-06-29 08:45:55 +0900 (Wed, 29 Jun 2016)

  New Revision: 55531

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55531

  Log:
    Passed block symbol to proc
    
    * proc.c (passed_block): convert passed block symbol to proc.
      based on the patch by Daisuke Sato in [ruby-dev:49695].
      [Bug #12531]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_symbol.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55530)
+++ ChangeLog	(revision 55531)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 29 08:45:53 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (passed_block): convert passed block symbol to proc.
+	  based on the patch by Daisuke Sato in [ruby-dev:49695].
+	  [Bug #12531]
+
 Wed Jun 29 03:34:41 2016  NARUSE, Yui  <naruse@r...>
 
 	* bignum.c (rb_big2ulong): the old logic seems to try to avoid
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 55530)
+++ test/ruby/test_symbol.rb	(revision 55531)
@@ -229,6 +229,35 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L229
     assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block")
   end
 
+  def test_block_curry_proc
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = proc { true }.curry
+    assert(b.call, "without block")
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
+  def test_block_curry_lambda
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = lambda { true }.curry
+    assert(b.call, "without block")
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
+  def test_block_method_to_proc
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = method(:tap).to_proc
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
   def test_succ
     assert_equal(:fop, :foo.succ)
   end
Index: proc.c
===================================================================
--- proc.c	(revision 55530)
+++ proc.c	(revision 55531)
@@ -820,6 +820,9 @@ passed_block(VALUE pass_procval) https://github.com/ruby/ruby/blob/trunk/proc.c#L820
 {
     if (!NIL_P(pass_procval)) {
 	rb_proc_t *pass_proc;
+	if (SYMBOL_P(pass_procval)) {
+	    pass_procval = sym_proc_new(rb_cProc, pass_procval);
+	}
 	GetProcPtr(pass_procval, pass_proc);
 	return &pass_proc->block;
     }

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

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