From: Alan Moore Date: 2001-10-07T03:39:58+09:00 Subject: [ruby-talk:22163] Re: Match expressions matz wrote: >I often confuse left and right even after I've grown up. That _was_ one of my theories... ;-) >This should be: > > case NODE_MATCH3: > { > VALUE r = rb_eval(self,node->nd_recv); > VALUE l = rb_eval(self,node->nd_value); > if (TYPE(l) == T_STRING) { > result = rb_reg_match(r, l); > } > else { > result = rb_funcall(l, match, 1, r); > } > } > break; So, given the expression "node1 =~ node2", if node1 is a literal regex (i.e., /xyz/ or %{xyz}), Ruby translates the expression to "node1.=~(node2)". If node2 is a literal regex, and node1 evaluates to a string, Ruby does a "node2.=~(node1)". In both cases, it calls the rb_reg_match function directly, as a speed optimization. But if node1 doesn't evaluate to a string, Ruby turns it around again and does a "node1.=~(node2)", under the assumption that node1 is a user- defined object that defines its own "=~" method. Is that right? Is that what you meant, Guy? --Alan