Class: Recruit::Duck

Inherits:
Object
  • Object
show all
Defined in:
lib/speq/recruit.rb

Overview

Mostly just quacks like one

Instance Method Summary collapse

Constructor Details

#initialize(**mapping) ⇒ Duck

Returns a new instance of Duck.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/speq/recruit.rb', line 17

def initialize(**mapping)
  mapping.each do |method_name, value|
    if mapping[method_name].respond_to?(:call)
      define_singleton_method(method_name, value)
    else
      define_singleton_method(method_name, &-> { mapping[method_name] })
      define_singleton_method(
        "#{method_name}=".to_sym,
        &->(val) { mapping[method_name] = val }
      )
    end
  end
end