Method: Exchange#method_missing

Defined in:
lib/soaspec/exchange.rb

#method_missing(method_name, *args, &block) ⇒ Object

Implement undefined setter with []= for FactoryBot to use without needing to define params to set

Parameters:

  • method_name (Object)
  • args (Object)
  • block (Object)


152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/soaspec/exchange.rb', line 152

def method_missing(method_name, *args, &block)
  if method_name[-1] == '=' # A setter method
    if args.first.class < Exchange # This would be prerequisite exchange
      define_singleton_method(method_name[0..-2]) do
        args.first
      end
    else
      self[method_name[0..-2]] = args.first
    end
  else
    super
  end
end