在课堂Foo
上,我想Bar
在某些条件下包含方法:
module Bar
def some_method
"orly"
end
end
class Foo
def initialize(some_condition)
if !some_condition
"bar"
else
class << self; include Bar; end
end
end
end
有没有更简洁(更清晰)的方法来实现include
方法中的,而不必在单例类中进行?