Is there a way to "flatten" nested modules so that all of their methods can be used when extending another class or module? For ex开发者_运维问答ample:
class User
extend UserStats
end
module UserStats
module Current
def active
where('status = "active"')
end
end
end
I want to be able to extend UserStats (or User) such that the methods in UserStats::Current are available as class methods for User.
I tried "extend Current" in UserStats, but that doesn't seem to work. Is there any way to do this?
Why not just extend UserStats::Current
?
Do you mean something like this?
module UserStats
def self.extended(klass)
klass.send(:extend, Current)
end
module Current
def active
puts "test"
end
end
end
class User
extend ::UserStats
end
puts User.active
精彩评论