class Symbol def coerce(other) # Symbol#coerce を定義する equiv = { K: 2 ** 10, # 2の10乗 1,024 M: 2 ** 20, # 2の20乗 1,048,576 G: 2 ** 30, # 2の30乗 1,073,741,824 } if (other.kind_of? Numeric) && (val = equiv[self]) [other, val] else raise end end end p 1 * :K #=> 1024 (計算できるようになる) p 1 * :M #=> 1048576 ( 〃 ) p 1 * :G #=> 1073741824 ( 〃 )