module PIM::Utils::GetterSetterAware

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File pim.rb, line 1619
def method_missing name, *args, &block

  method_name = name.to_s

  match = /^(get|set)_([[:lower:]].*)$/.match(method_name)
  if match.nil?
    match = /^(get|set)([[:upper:]].*)$/.match(method_name)
    snakeize = true
  end
  super if match.nil?

  # Only allow 'set' if exactly one argument is provided!
  method_type = match[1]
  super if method_type == 'set' and args.size != 1

  # Convert property name to snake case if necessary
  property_name = match[2]
  property_name = PIM::Utils.snakeize(property_name) if snakeize

  # Check if instance variable exists
  instance_var_name = ('@' + property_name)
  if self.instance_variable_defined?(instance_var_name)

    if method_type == 'get'
      return self.instance_variable_get(instance_var_name)
    elsif method_type == 'set' and !args.empty?
      return self.instance_variable_set(instance_var_name, *args)
    end

  end

  # Check if method exists
  get_method_name = property_name.to_sym
  set_method_name = (property_name + '=').to_sym
  if method_type == 'get' and self.respond_to?(get_method_name)
    return self.send(get_method_name)
  elsif method_type == 'set' and self.respond_to?(set_method_name)
    return self.send(set_method_name, *args)
  end

  super

end