# Inheriting Array and slice() behaviour

**URL:** <https://rubytalk.org/t/inheriting-array-and-slice-behaviour/19382>\
**Category:** ruby-talk\
**Created:** [7 July 2005 00:00 UTC](https://rubytalk.org/t/inheriting-array-and-slice-behaviour/19382 "2005-07-07T00:00:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devin\_Mullins](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Devin\_Mullins](https://rubytalk.org/u/Devin_Mullins)\
**Post date:** [7 July 2005 00:00 UTC](https://rubytalk.org/t/inheriting-array-and-slice-behaviour/19382/1 "2005-07-07T00:00:07Z")

</div>

> \>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/ThinkingInRuby.red](http://onestepback.org/index.cgi/Tech/Ruby/ThinkingInRuby.red) for a vaguely related, and much more eloquent, example of what I'm talking about.)  
3. Sorry! I'll stop bothering you now.

Devin
