Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2つのサブクラス化配列を連結しようとしました。
ただし、MyArrayではなくArrayクラスを返します。
class MyArray < Array end foo = MyArray.new bar = MyArray.new p foo.class #=> MyArray p (foo + bar).class #=> Array
MyArrayクラスを連結するにはどうすればよいですか?
MyArrayクラスでメソッドを定義し、を使用しますsuper。また、alias_method:+、:concatを使用することもできます。
super
def concat(some_array) super end p foo.concat(bar).class #=> MyArray