Ruby Refinements - Silver/Gold試験対策
class String def hello self + "hello" end end
オープンクラスでのメソッド定義は影響が大きすぎるため、 範囲を限定する為に、refinements を利用可能
・ファイル内限定 ・usingはトップレベル、クラス、モジュール直下限定 ・メソッド内利用不可
class B def good_night "おやすみになる" end end module A refine B do def good_night "大殿ごもる" end end end p B.new.good_night #=> "おやすみになる" using A p B.new.good_night #=> "大殿ごもる"