Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/sinject/class.rb

Instance Method Summary collapse

Instance Method Details

#dependency(*obj_key) ⇒ Object

Specify a dependency required by a class. This will create an attribute for the required dependency that will be populated by the ioc container.

Example:

>> dependency :registered_object_symbol

Arguments:

key:  (Symbol)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sinject/class.rb', line 11

def dependency(*obj_key)
  obj_key.each do |k|

    self.send(:define_method, k) do
      val = self.instance_variable_get("@#{k}")
      if(val == nil)
        val = Sinject::Container.instance.get(k)
        self.instance_variable_set("@#{k}", val)
      end
      val
    end

  end
end