Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Rubyで匿名モジュールを再度開くことは可能ですか?以下は機能しません。
m = Module.new module m end
"SyntaxError:(eval):2:クラス/モジュール名はCONSTANTである必要があります"。
はい。ただし、定数を使用する必要があります。
M = Module.new module M end
することもできますM = m。
M = m
別の方法:
m = Module.new do def self.foo1 1 end end m.class_eval do def self.foo2 2 end end m.foo1 + m.foo2 #=> 3