Project

General

Profile

Actions

Bug #10845

closed

Subclassing String

Added by sawa (Tsuyoshi Sawada) almost 10 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:68084]

Description

If I make a subclass of String, the method * returns an instance of that class.

class MyString < String
end

MyString.new("foo").*(2).class #=> MyString

This is different from other similar operations like + and %, which return a String instance.

MyString.new("foo").+("bar").class #=> String
MyString.new("%{foo}").%(foo: "bar").class #=> String

I don't see clear reason why * is to be different from + and %, and thought that perhaps either the behaviour with * is a bug, or the behaviour with + and % is a bug.

Or, is a reason why they are different?


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #6087: How should inherited methods deal with return values of their own subclass? Closedmatz (Yukihiro Matsumoto)Actions
Has duplicate Ruby master - Bug #11209: [PATCH] Fix for String#+ when subclassedClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0