2012-07-21から1日間の記事一覧

Rubyでモジュール関数を定義する

モジュール関数の例をあげるとMathモジュールのsqrtメソッド. Math.sqrt 4 # => 2 include Math sqrt 4 # => 2 self.sqrt 4 # これは無理 自分でもこのようなモジュール関数を定義するには, module_functionメソッドを使います. module Hoge def hello puts …