From: "David A. Black" Date: 2005-07-07T01:24:43+09:00 Subject: Re: Inheriting Array and slice() behaviour Hi -- On Thu, 7 Jul 2005, Sylvain Joyeux wrote: >> What return type do you want? Arrays or Expressions? You can force >> return values back to Arrays with #to_a, or manually make Expressions >> with something like >> >> y = Expression.new(x.slice(1..5).to_a) > > I find it VERY weird to build anything else than an Array here. Array now > nothing about Expression, so I don't see how - in general - it could build > a well-formed Expression object But remember... you're not calling Array#slice; you're calling Expression#slice. It may reside in Array, but that doesn't mean it has to return an array. It might assume that anything derived from Array is "sliceable", so to speak. By way of contrast: class A < Array; end a = A.new.concat([1,2,3,4]) a.select {|x| x < 3 } .class # Array (not A) In that case, Array is used as the "normalized" form for returning results, because Enumerable#select cannot know whether A objects are suitable as containers. (At least, that's how I've understood it.) David -- David A. Black dblack@wobblini.net