[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Inheriting Array and slice() behaviour

Devin Mullins

7/7/2005

> |Like the OP, I think it's weird and special-cased to have #slice
> |magically return something with the receiver's class. Especially since
> |the return value is going to be broken (not initialized) except in
> |trivial cases.
>
> What if it can be initialized properly?

True... Array has a "copy constructor" (Array.new can take another Array), so you could call klass.new(theNewSubArray) unless klass == Array, instead of just massaging it into a klass...

1. I might be missing the point. I often do.
2. I don't have a strong opinion on the matter, though I do see the benefit of making this work better. It's all about "lowering the barrier to entry" to extending the core classes. (See http://onestepback.org/index.cgi/Tech/Ruby/Thinking... for a vaguely related, and much more eloquent, example of what I'm talking about.)
3. Sorry! I'll stop bothering you now.

Devin