module CyberCoach::HashInitializable::InstanceMethods

The instance methods to install.

Initialization

↑ top

Public Instance Methods

initializable_with() click to toggle source

Returns a list of instance variables it can be initialized with.

# File lib/cybercoach/hash_initializable.rb, line 29
def initializable_with
  fail SubclassResponsibilityError
end
initialize_with(hash) click to toggle source

Initializes the instance variables with a name in the specified names to the values mapped in the specified hash.

hash

A hash of values to set on instance variables.

names

The names of the instance variables to set.

# File lib/cybercoach/hash_initializable.rb, line 41
def initialize_with(hash)
  initializable_with.each do |name|
    if hash.key? name
      instance_variable_set(:"@#{name}", hash[name])
    end
  end
end