From: David Alan Black Date: 2001-09-26T08:18:40+09:00 Subject: [ruby-talk:21698] Re: Help understanding self ... Hello -- On Wed, 26 Sep 2001, Phil Mitchell wrote: > Okay, but according to Ruby library reference, and pickaxe, [] is a method in > class Hash. A method that is called with no receiver is sent to self. So, [] > is not exactly a method. Then, how should I understand it? Hash#[] is definitely a method. That's not the issue; the issue is whether a given [] is a method *call*. In this case: class Hash def thing [1] end end that "[1]" is an array. That's how the parser sees it. So there's no method call, therefore no violation of the rule that a method called with no receiver is sent to self. It comes down to finding a way for "[]" to mean different things. Where there might be ambiguity, some decision has to be made. Another example is: puts class This causes an error, because even though there's a method Object#class, the bare "class" is parsed as the keyword "class", and then having nothing come after it makes no sense. It's not a call to method #class that behaves strangely; it's not a method call at all. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav