Module: DependencyInjector

Defined in:
lib/dependency_injector.rb,
lib/dependency_injector/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#def_injector(method_name, &default) ⇒ Object

A simple macro for creating an easy dependency injector.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dependency_injector.rb', line 5

def def_injector(method_name, &default)
  attr_writer method_name

  define_method(method_name) do
    if returning_value = instance_variable_get("@#{method_name}")
      returning_value
    else

      returning_value = instance_eval(&default)
      instance_variable_set("@#{method_name}", returning_value)
      returning_value
    end
  end
  private method_name
end