Sha256: ed01e556716eaf3971640e092bd8fffc4cbb7248648186288b4c64e135475f25
Contents?: true
Size: 486 Bytes
Versions: 11
Compression:
Stored size: 486 Bytes
Contents
class Hash class Builder def initialize @hash = {} @scopes = [] end def build yield self @hash end def method_missing(method, *args, &block) if block @scopes.push method block.call @scopes.pop else current_scope = @scopes.inject(@hash) { |h,s| h[s] ||= {} } current_scope[method] = args.first end end def self.build(&block) new.build(&block) end end end
Version data entries
11 entries across 11 versions & 1 rubygems