Module: Hws::Connectors::Helper::ClassMethods

Defined in:
lib/hws-connectors/helper.rb

Instance Method Summary collapse

Instance Method Details

#option(param, block = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hws-connectors/helper.rb', line 9

def option(param, block = nil)
  [self, self.class].each do |_class|
    _class.class_eval do
      attr_accessor(param)
      next if block.nil?

      define_method(param) do
        instance_variable_set("@#{param}", block.call) if instance_variable_get("@#{param}").nil?
        instance_variable_get("@#{param}")
      end
    end
  end
end