aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--proc.c3
-rw-r--r--test/ruby/test_symbol.rb29
3 files changed, 38 insertions, 0 deletions
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 <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
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