Tim Hunter
4/23/2007 12:47:00 AM
Andrew Green wrote:
>>> Is it possible to use -> as a method name in Ruby?
>>>
>>>
>>>
>> No. A subset of Ruby's operators are implemented as methods. '>>' is one
>> of those operators. '->' isn't a Ruby operator at all.
>>
>> The operators that are implemented as methods are: [], []=, **, !, ~, +,
>> -, *, /, %, <<, >>,& ^, |, <=>, <=, <, >, >=, ==, ===, and =~.
>>
>>
>
> So is there no way to make '->' an operator and define its behavior?
>
> If not, what about '=>'?
>
>
>
I listed the Ruby operators that are implemented as methods. '=>' isn't
in the list, is it?
Now, for completeness' sake, it actually is possible to define a method
named '->', but the only way you could call it would be by using 'send',
and I'm guessing you don't want to do that. It would look like this:
o.send('->', args)