I'm trying to make an Array-like class with chainable methods, but I seem to be screwed because Ruby's Array methods call ::Array.new instead of self.class.new:
class MyArray < Array; end
x = MyArray.new
y = MyArray.new
(x+y).class # Array, expected MyArray!
I understand that I could go through and re-implement all of Array's methods which call its constructor, but that seems really bogus.
Interestingly, Set DOES work 'correctly':
class MySet < Set; end
x = MySet.new([1,2,3])
y = MySet.new([4,5,6])
(x+y).class # MySet -- yeah!
What am I missing? Is there a Ruby idiom for subclassing Array in this way? Thanks!