include における定数のスコープ
参考:
include したメソッドで呼び出す定数のスコープの話 – Qiita
ミックスインしてもプライベートなスコープの作り方
モジュール内で自分自身に refine を適用する
module Greeter
using Module.new {
refine Greeter do
def world
"world"
end
end
}
def hello
"hello, #{world}"
end
end
class Stuff
include Greeter
def greet
hello
end
def greet2
world
end
end
p Stuff.new.greet # => "hello, world"
p Stuff.new.greet2 # => undefined local variable or method 'world'
参考: