tags:

views:

93

answers:

3

I'd like to read the logic code of =, but can't find it.

UPDATE:

I found the test_multi method text/ruby/test_assignment.rb. It's Ruby code, but seems will let me to the destination.

The reason I want to check the code is find how it handles multi-assignment. Like a,b,c = [1,2,3].

UPDATE:

I found keywords "MASGN" and led me to

compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped) in compile.c

http://github.com/ruby/ruby/commit/e39eb9dab50eaa681467e51145b37cdc11667830#diff-2

+1  A: 

I don't think you'll find any code for =.

The = will be part of the grammar rules which define the Ruby language and the parser(written in C) will make use of the grammar.

codaddict
+1  A: 
Jörg W Mittag
+1  A: 

http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_2/parse.y line 1088-1116

| var_lhs tOP_ASGN command_call
        {
        /*%%%*/
        value_expr($3);
        if ($1) {
            ID vid = $1->nd_vid;
            if ($2 == tOROP) {
            $1->nd_value = $3;
            $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
            if (is_asgn_or_id(vid)) {
                $$->nd_aid = vid;
            }
            }
            else if ($2 == tANDOP) {
            $1->nd_value = $3;
            $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
            }
            else {
            $$ = $1;
            $$->nd_value = NEW_CALL(gettable(vid), $2, NEW_LIST($3));
            }
        }
        else {
            $$ = NEW_BEGIN(0);
        }
        /*%
        $$ = dispatch3(opassign, $1, $2, $3);
        %*/
        }
zzzhc