Project

General

Profile

ActionsLike0

Bug #10845

closed

Subclassing String

Added by sawa (Tsuyoshi Sawada) about 10 years ago. Updated over 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 - Bug #6087: How should inherited methods deal with return values of their own subclass? Closedmatz (Yukihiro Matsumoto)Actions
Has duplicate Ruby - Bug #11209: [PATCH] Fix for String#+ when subclassedClosedActions

Updated by marcandre (Marc-Andre Lafortune) almost 10 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
#5

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago

  • Has duplicate Bug #11209: [PATCH] Fix for String#+ when subclassed added
#6

Updated by mame (Yusuke Endoh) over 5 years ago

  • Related to Bug #6087: How should inherited methods deal with return values of their own subclass? added
#7

Updated by mame (Yusuke Endoh) over 5 years ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed
ActionsLike0

Also available in: Atom PDF