https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-05-05T15:32:39ZRuby Issue Tracking SystemRuby master - Feature #15824: respond_to pattern for pattern matchhttps://redmine.ruby-lang.org/issues/15824?journal_id=779192019-05-05T15:32:39Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I don't want to comment so much on the issue as such, but I would like to point<br>
out that it may be a better idea to start with a new idea not on highest<br>
complexity. I am not sure if everyone fully understood pattern matching yet so<br>
in my personal opinion it may be better to see how pattern matching is used<br>
before making it more complex (including syntactic changes). But that's just<br>
my opinion, anyway; some of the syntax appears to become no longer recognizable<br>
ruby (to me).</p> Ruby master - Feature #15824: respond_to pattern for pattern matchhttps://redmine.ruby-lang.org/issues/15824?journal_id=781422019-05-22T08:57:51Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Interesting idea. We need to investigate the idea further.</p>
<p>Matz.</p> Ruby master - Feature #15824: respond_to pattern for pattern matchhttps://redmine.ruby-lang.org/issues/15824?journal_id=785852019-06-14T23:42:39Zktsj (Kazuki Tsujimoto)kazuki@callcc.net
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/14912">Feature #14912</a>: Introduce pattern matching syntax</i> added</li></ul> Ruby master - Feature #15824: respond_to pattern for pattern matchhttps://redmine.ruby-lang.org/issues/15824?journal_id=819172019-10-06T07:56:01Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul></ul><p>The implementation can be very simple.<br>
(I don't know whether <code>NODE_METHREF</code> is suitable.)</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">diff --git a/compile.c b/compile.c
index 7a88f81daa..f6eafb0ac2 100644
</span><span class="gd">--- a/compile.c
</span><span class="gi">+++ b/compile.c
</span><span class="p">@@ -5888,6 +5888,11 @@</span> iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
ADD_LABEL(ret, fin);
break;
}
<span class="gi">+ case NODE_METHREF: {
+ ADD_INSN1(ret, line, putobject, ID2SYM(node->nd_mid));
+ ADD_SEND(ret, line, idRespond_to, INT2FIX(1));
+ break;
+ }
</span> default:
UNKNOWN_NODE("NODE_IN", node, COMPILE_NG);
}
<span class="gh">diff --git a/parse.y b/parse.y
index 287704e14f..dd305479f5 100644
</span><span class="gd">--- a/parse.y
</span><span class="gi">+++ b/parse.y
</span><span class="p">@@ -3904,6 +3904,10 @@</span> p_expr_basic : p_value
{
$$ = $2;
}
<span class="gi">+ | '.' operation2
+ {
+ $$ = NEW_METHREF(Qundef, $2, &@$);
+ }
</span> ;
p_args : p_expr
</code></pre>
<p>By the way, missing "& pattern" seems to be intended. see <a href="/issues/14912">[ruby-core:88036]</a> <a href="https://bugs.ruby-lang.org/issues/14912#note-7" class="external">https://bugs.ruby-lang.org/issues/14912#note-7</a> .</p>