Class: Sublime::Hash2Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/candlepin-api/hash2instance.rb

Overview

Superclass that turns any hashes in the argument list into settings for instance variables. If the instance variable has a writer method, that’s used to set the value – otherwise it’s set with #instance_variable_set.

Direct Known Subclasses

CandlepinAPI::Endpoint

Instance Method Summary collapse

Constructor Details

#initialize(*args_p) ⇒ nil

Any hashes in the argument list are extracted, and each key/value pair is treated as a potential setting for an instance variable. If there is a writer method for the key, it is called to set the instance variable with the given value.

Parameters:

  • args_p (Array)

    Variable-length argument list.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/candlepin-api/hash2instance.rb', line 26

def initialize(*args_p)
 args_p.select { |o| o.kind_of?(Hash) }.each do |hsh_p|
    hsh_p.each do |k,v|
      ivwriter	= (k.to_s + '=').to_sym
      ivname	= ('@' + k.to_s).to_sym
      if (self.class.method_defined?(ivwriter))
        self.send(ivwriter, v)
      else
        self.instance_variable_set(ivname, v)
      end
    end
  end
end