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


書籍 Ruby Cookbook | Mixing in Class Methods

パンくず

Ruby Cookbook
Mixing in Class Methods

概要

Mixing in Class Methods

内容

クラスメソッドのMixinをする場合、
サブモジュールを作成し,メインのモジュールのself.includedメソッド
レシーバを拡張する。

サンプルコード

# encoding: Windows-31J

module Hogeable
  module HogeClassMethods
    def hoge
      puts "hoge!"
    end
  end
  
  def self.included(receiver)
    receiver.extend(HogeClassMethods)
  end
end

class Hoge
  include Hogeable
end

Hoge.hoge

出力

hoge!



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

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