Module: FlazmRubyHelpers::ClassHelper
- Defined in:
- lib/flazm_ruby_helpers/class_helper.rb
Overview
Define methods to handle default initialization behavior
Instance Method Summary collapse
Instance Method Details
#initialize_variables(config = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/flazm_ruby_helpers/class_helper.rb', line 6 def initialize_variables(config = {}) # define the defaults method in the class that includes this # defaults method returns a hash of instance variables mapped to values defaults.each_pair do |key, default_value| key = key.to_s if config[key] instance_variable_set("@#{key}", config[key]) elsif ENV[key.upcase.to_s] instance_variable_set("@#{key}", ENV[key.upcase.to_s]) else instance_variable_set("@#{key}", default_value) end end end |