我有一个包含模块的 Ruby 类。我希望包含类的行为类似于 OpenStruct。我如何在不显式继承 OpenStruct 的情况下实现这一点?
class Book
include MyModule
end
module MyModule
def self.included(klass)
# Make including class behave like OpenStruct
end
end
代替
class Book < OpenStruct
include MyModule
end