😸
[Feature #21148] 数値に対する抽象的なクラスを追加する提案
[Feature #21148] Class proposal: IndefiniteNumeric < Numeric
- 以下のような
数値
に対する抽象的なクラスを定義する提案
class IndefiniteNumeric < Numeric
def coerce(other) = value.coerce(other)
def +(other) = value + other
def -(other) = value - other
def *(other) = value * other
def /(other) = value / other
def <=>(other) = value <=> other
end
- このクラスを継承し
#value
メソッドを定義することで数値のように四則演算などが利用できるように振る舞うクラスを定義したい感じなんですかね? - コメントでも指摘されていますがクラスというよりかはどちらかというと
Comparable
みたいなモジュールの定義になりそう? - うーん、あると利用するかも?っていうぐらいの印象なんですが実際に利用するケースがどれぐらいあるのかなあ
Discussion