< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #10845 has been updated by Eregon (Benoit Daloze).
@ioquatix See #6087. Returning subclass instances leads to all kind of issues, because there is no good way to build the subclass instance.
+1 to do it for String since we did for Array.
Maybe we should do it for Hash too?
It seems already the case for most Hash methods but not all (e.g. `Hash#merge`).
----------------------------------------
Bug #10845: Subclassing String
https://bugs.ruby-lang.org/issues/10845#change-88639
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
If I make a subclass of `String`, the method `*` returns an instance of that class.
~~~ruby
class MyString < String
end
MyString.new("foo").*(2).class #=> MyString
~~~
This is different from other similar operations like `+` and `%`, which return a `String` instance.
~~~ruby
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?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>