From: Kristof Bastiaensen Date: 2004-04-29T20:54:14+09:00 Subject: Re: alias or alias_method problem Hi, On Thu, 29 Apr 2004 10:11:42 +0900, Angel Martin wrote: >> > Try the following instead: >> > >> > class Hash #hash[] === hash[nil] >> > alias_method "old_bracket_assign", "[]=" >> > alias_method "old_bracket" ,"[]" >> > def []=(*ag) >> > value=ag.pop >> > return old_bracket_assign(nil, value) if ag.size<1 >> > old_bracket_assign(*(ag.push(value))) >> > end >> > def [](*ag) >> > return old_bracket(nil) if ag.size<1 >> > old_bracket(*ag) >> > end >> > end >> > Ok, works great but when i tried: > return _[]=(nil, value) if ag.size<1 > it protest with a aprox: "cannot assign to nil" If you write _[]=(nil, value), ruby will interprete it as: (_)[] = (nil, value) #meaning (_).[]=((nil, value)) Which is invalid syntax, because (nil, value) as an expression is illegal. (The "cannot assign to nil" response is kind of a mystery to me...) When written as: _.[]=(nil, value) it will work, assuming _ contains something useful. for example: _ = {} _.[]=(nil, 4) _[nil] => 4 > regards > Angel, Hope this explanation helps. Kristof