astux7/ruby_method.md
– モジュールメソッドをクラスのインスタンスで使用できるようにします。 これは言語レベルのものです。 include メソッドは、他のモジュール (通常、ミックスインと呼ばれます) を使用してクラスを「拡張」する主な方法です。
module Afterendclass Example include AfterendExample.ancestors# =>
– 別のファイルを実行します。
– 別のファイルを実行します。また、過去に要求したものを追跡し、同じファイルを2度要求することはありません。例えば、rspec クラスが /spec ディレクトリにあり、それらのデータが thespec/data ディレクトリにある場合、テストケースでは次の行を使用します:
require_relative "data/test"
– 実行コード用。
– 拡張クラスを、拡張クラスのシングルトン クラスの祖先に追加することになります。
module After def module_method puts "Module Method invoked" endendclass Exampleendex = Example.newex.extend Afterex.module_method# => Module Method invoked
– モジュールの機能をクラスに組み込み、クラス自身がこれらのメソッドを利用できるようにします。
module After def module_method puts "Module Method invoked" endendclass Exampleendex = Example.newex.extend Afterex.module_method# => Module Method invoked
– オーバーライドするメソッドによって、オーバーライドされたメソッド呼び出しに使用されます。