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

ruby-changes:41077

From: shugo <ko1@a...>
Date: Wed, 16 Dec 2015 19:35:46 +0900 (JST)
Subject: [ruby-changes:41077] shugo:r53152 (trunk): * vm.c (vm_make_proc_from_block): should convert a Symbol to a Proc.

shugo	2015-12-16 19:35:34 +0900 (Wed, 16 Dec 2015)

  New Revision: 53152

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

  Log:
    * vm.c (vm_make_proc_from_block): should convert a Symbol to a Proc.
      [ruby-core:72083] [Bug #11811]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_lazy_enumerator.rb
    trunk/vm.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53151)
+++ ChangeLog	(revision 53152)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 16 19:30:56 2015  Shugo Maeda  <shugo@r...>
+
+	* vm.c (vm_make_proc_from_block): should convert a Symbol to a Proc.
+	  [ruby-core:72083] [Bug #11811]
+
 Wed Dec 16 16:17:34 2015  Eric Wong  <e@8...>
 
 	* test/ruby/test_io.rb: fix spelling errors
Index: vm.c
===================================================================
--- vm.c	(revision 53151)
+++ vm.c	(revision 53152)
@@ -567,6 +567,10 @@ vm_make_proc_from_block(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm.c#L567
 	*procptr = block->proc = rb_vm_make_proc(th, block, rb_cProc);
 	return TRUE;
     }
+    else if (SYMBOL_P(block->proc)) {
+	*procptr = rb_sym_to_proc(block->proc);
+	return TRUE;
+    }
     else {
 	*procptr = block->proc;
 	return FALSE;
Index: test/ruby/test_lazy_enumerator.rb
===================================================================
--- test/ruby/test_lazy_enumerator.rb	(revision 53151)
+++ test/ruby/test_lazy_enumerator.rb	(revision 53152)
@@ -532,4 +532,11 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L532
     assert_warning("") {le.drop(1).force}
     assert_warning("") {le.drop_while{false}.force}
   end
+
+  def test_symbol_chain
+    assert_equal(["1", "3"], [1, 2, 3].lazy.reject(&:even?).map(&:to_s).force)
+    assert_raise(NoMethodError) do
+      [1, 2, 3].lazy.map(&:undefined).map(&:to_s).force
+    end
+  end
 end

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

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