David A. Black wrote:
> Hi --
> 
> On Sun, 1 Aug 2010, Brian Candler wrote:
> 
>> Maurizio De Santis wrote:
>>> why??
>>
>> What ruby are you using? With ruby 1.8.7 (2010-01-10 patchlevel 249)
>> [x86_64-linux] and your posted code, I get the following output:
>>
>> ["a", "ab"]
>> "b"
>> ert.rb:17:in `[]': can't convert Regexp into Integer (TypeError)
>>  from ert.rb:17
>>
>> If I change it to
>>
>>  alias_method :slice_without_regexp, :slice
>>  alias_method :slice, :slice_with_regexp
>>  alias_method :[], :slice_with_regexp
>>
>> then *that* gives a stack too deep error, but on the initial slice call.
>>
>> I'm afraid I don't know the solution though. I suspect slice is already
>> an alias for [], or vice versa.
> 
> They are indeed the same method:
> 
>     rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
>     rb_define_method(rb_cArray, "slice", rb_ary_aref, -1);

Though, technically they're synonyms, not aliases. :)

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13301

Regards,

Dan