Class: Orchparty::HashBuilder

Inherits:
Builder
  • Object
show all
Defined in:
lib/orchparty/dsl_parser.rb

Direct Known Subclasses

VariableBuilder

Instance Method Summary collapse

Methods inherited from Builder

build

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_, *values, &block) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/orchparty/dsl_parser.rb', line 131

def method_missing(_, *values, &block)
  if block_given?
    value = HashBuilder.build(block)
    if values.count == 1
      @hash ||= AST.hash
      @hash[values.first.to_sym] = value
    else
      @hash ||= AST.array
      @hash << value
    end
  else
    value = values.first
    if value.is_a? Hash
      @hash ||= AST.hash
      key, value = value.first
      @hash[key.to_sym] = value
    else
      @hash ||= AST.array
      @hash << value
    end
  end
  self
end

Instance Method Details

#_buildObject



155
156
157
# File 'lib/orchparty/dsl_parser.rb', line 155

def _build
  @hash
end