Commit 99bef96d authored by Fabio Pelosin's avatar Fabio Pelosin

Add Pod::DependencyInjection

parent d96c2c98
module Pod
# Provides basic support for Dependency Injection in a class.
#
module DependencyInjection
# Declares a dependency in another class specifying a default. The class
# implementing this method should should initialize the dependency
# accessing this property.
#
# @param [Symbol] name
# the name of the dependency.
#
# @param [Class] default_class
# the default class to use for the dependency.
#
# @return [void]
#
def dependency(name, default_class)
singleton_class.class_eval do
attr_writer name
define_method(name) { instance_variable_get("@#{name}") || default_class }
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment