diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-28 23:45:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-28 23:45:55 +0000 |
commit | 86a756ae154ff42da39af1a5358506fca11e0946 (patch) | |
tree | a0c7dedaaa6526d8ec61196b357415256259f24c | |
parent | e3503ee218d8b6ca4dfa95414fe5d83b52104476 (diff) | |
download | ruby-86a756ae154ff42da39af1a5358506fca11e0946.tar.gz |
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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | proc.c | 3 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 29 |
3 files changed, 38 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Wed Jun 29 08:45:53 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * bignum.c (rb_big2ulong): the old logic seems to try to avoid @@ -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 |