From 86a756ae154ff42da39af1a5358506fca11e0946 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 28 Jun 2016 23:45:55 +0000 Subject: [PATCH] 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ proc.c | 3 +++ test/ruby/test_symbol.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4d69391762..aeb9b9463d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jun 29 08:45:53 2016 Nobuyoshi Nakada + + * 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 * bignum.c (rb_big2ulong): the old logic seems to try to avoid diff --git a/proc.c b/proc.c index 850de22634..29a857f4a4 100644 --- a/proc.c +++ b/proc.c @@ -820,6 +820,9 @@ passed_block(VALUE pass_procval) { 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; } diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 03934226a1..d8c91c1eea 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -229,6 +229,35 @@ class TestSymbol < Test::Unit::TestCase 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