Methods
Public Class methods
[ show source ]
# File lib/facets/more/hashbuilder.rb, line 32 def self.build( blockstr=nil, &block ) self.new.build( blockstr, &block ).to_h end
[ show source ]
# File lib/facets/more/hashbuilder.rb, line 36 def initialize( blockstr=nil, &block ) @hash = {} @flag = {} end
Public Instance methods
[ show source ]
# File lib/facets/more/hashbuilder.rb, line 41 def build( blockstr=nil, &block ) raise "both string and block given" if blockstr and block_given? if blockstr instance_eval blockstr else instance_eval &block end self # or to_h ? end
[ show source ]
# File lib/facets/more/hashbuilder.rb, line 53 def method_missing( sym, *args, &block ) sym = sym.to_s.downcase.chomp('=') if @hash.key?(sym) unless @flag[sym] @hash[sym] = [ @hash[sym] ] @flag[sym] = true end if block_given? @hash[sym] << self.__class__.new( &block ).to_h else @hash[sym] << args[0] end else if block_given? @hash[sym] = self.__class__.new( &block ).to_h else @hash[sym] = args[0] end end end
[ show source ]
# File lib/facets/more/hashbuilder.rb, line 51 def to_h ; @hash ; end