ruby-changes:64437
From: zverok <ko1@a...>
Date: Tue, 22 Dec 2020 09:22:57 +0900 (JST)
Subject: [ruby-changes:64437] 816bbfdc87 (master): Document Proc#==
https://git.ruby-lang.org/ruby.git/commit/?id=816bbfdc87 From 816bbfdc87d4a5f600f28cf4b0eaa5161af80645 Mon Sep 17 00:00:00 2001 From: zverok <zverok.offline@g...> Date: Mon, 21 Dec 2020 23:15:47 +0200 Subject: Document Proc#== diff --git a/proc.c b/proc.c index 749b6a8..06a6b80 100644 --- a/proc.c +++ b/proc.c @@ -1273,6 +1273,32 @@ rb_proc_get_iseq(VALUE self, int *is_proc) https://github.com/ruby/ruby/blob/trunk/proc.c#L1273 return NULL; } +/* call-seq: + * prc == other -> true or false + * prc.eql?(other) -> true or false + * + * Two proc are the same if, and only if, they were created from the same code block. + * + * def return_block(&block) + * block + * end + * + * def pass_block_twice(&block) + * [return_block(&block), return_block(&block)] + * end + * + * block1, block2 = pass_block_twice { puts 'test' } + * # Blocks might be instantiated into Proc's lazily, so they may, or may not, + * # be the same object. + * # But they are produced from the same code block, so they are equal + * block1 == block2 + * #=> true + * + * # Another Proc will never be equal, even if the code is the "same" + * block1 == proc { puts 'test' } + * #=> false + * + */ static VALUE proc_eq(VALUE self, VALUE other) { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/