モジュールを使用してクラスにメソッドを追加することは可能です。例:関数のRubyモジュール
class Test
include Singleton
end
方法で同じことを実行できますか?例えば、
class Test
include Singleton
def test
include Instructions_to_add_to_the_method
puts 'done'
end
end
:Test.instance.test
を呼び出すとき、私が欲しい
module Instructions_to_add_to_the_method
puts 'hi !'
end
:
hi !
done
それは私のスコープの問題を与えるだろうと私は、別のメソッドを呼び出すにしたくありません私の変数の。
いいえ、それはルビーの仕組みではありません。モジュールはマクロではありません。あなたが達成しようとしているのであれば、 'Module#prepend'または' Module#include'を 'super'と組み合わせて使用できますか? –