我有一个平面哈希:
hash = Hash["prop_one" => 100, "prop_two" => 200, "prop_three" => 300]
我将它包装在一个类中,该类公开这些值以通过访问器读取:
class WrappedHash
def prop_one
config['prop_one']
end
def prop_two
config['prop_two']
end
def prop_three
config['prop_three']
end
def initialize(config)
self.config = config
end
end
有没有办法将这些属性的请求代理到哈希,而无需手动添加访问器?(这是一个大哈希)