Method: HasAttributes#method_missing

Defined in:
lib/geoengineer/utils/has_attributes.rb

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

This method allows attributes to be defined on an instance without explicitly defining which attributes are allowed

The flow is:

  1. If the method receives a block, it will pass it to the assign_block method to be handled. By default this method will throw an error, but can be overridden by the class.

  2. If the method has one or more argument it will assume it is a setter and store the argument as an attribute.

  3. If the method has no arguments it will assume it is a getter and retrieve the value. If the retrieved value is a Proc it will execute it and store the returned value, this will allow for caching expensive calls and only calling if requested



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/geoengineer/utils/has_attributes.rb', line 75

def method_missing(name, *args, &block)
  name = name.to_s
  if block_given?
    # A class can override a
    assign_block(name, *args, &block)
  elsif args.length >= 1
    assign_attribute(name, args)
  elsif args.empty?
    retrieve_attribute(name)
  end
end