以下の内容はhttps://tbpgr.hatenablog.com/entry/20130825/1377435190より取得しました。


メタプログラミングRuby | 魔術 | オブジェクト拡張

概要

オブジェクト拡張

内容

オブジェクトの特異クラスにモジュールをインクルードして特異メソッドを定義。

サンプル

# encoding: utf-8
require "pry"

class Hoge
  def hoge
    puts "hoge"
  end
end

hoge = Hoge.new

module Hageable
  def hage
    puts "hage"
  end
end

class << hoge
  include Hageable
end

puts hoge.singleton_methods

出力

hage



以上の内容はhttps://tbpgr.hatenablog.com/entry/20130825/1377435190より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14