Build a hash programmatically via a fluent DSL-like syntax. In other words, this uses # to buld the hash.
# File lib/more/facets/hashbuilder.rb, line 61
61: def build!( blockstr=nil, &block )
62: raise "both string and block given" if blockstr and block_given?
63: if blockstr
64: instance_eval blockstr
65: else
66: instance_eval &block
67: end
68: self # or to_h ?
69: end
# File lib/more/facets/hashbuilder.rb, line 73
73: def method_missing( sym, *args, &block )
74: sym = sym.to_s.downcase.chomp('=')
75:
76: if @hash.key?(sym)
77: unless @flag[sym]
78: @hash[sym] = [ @hash[sym] ]
79: @flag[sym] = true
80: end
81: if block_given?
82: @hash[sym] << self.__class__.new( &block ).to_h
83: else
84: @hash[sym] << args[0]
85: end
86: else
87: if block_given?
88: @hash[sym] = self.__class__.new( &block ).to_h
89: else
90: @hash[sym] = args[0]
91: end
92: end
93:
94: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.