1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-06-28 23:45:55 +00:00
parent e3503ee218
commit 86a756ae15
3 changed files with 38 additions and 0 deletions

View file

@ -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

3
proc.c
View file

@ -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;
}

View file

@ -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