[Nitro] Singletons
transfire at gmail.com
transfire at gmail.com
Sun Feb 4 13:33:46 EST 2007
On Feb 4, 12:23 pm, "George Moschovitis"
<george.moschovi... at gmail.com> wrote:
> > http://onestepback.org/index.cgi/Tech/Ruby/
> > DependencyInjectionInRuby.rdoc
>
> I don't really want to add DI, IOC etc to Nitro. I would like to simplify
> Nitro and make it more accessible not include the most advanced concepts...
> What do others think?
Simple is good. I wouldn't want it if it's not so. Here's just a rough
concept, maybe this can give you more of a concrete idea of how it
could work and not be complex:
class Class
def needs *a
(@needs ||= []).concat(a.flatten.collect{|e|e.to_sym})
end
def need?(name)
@needs.include?(name.to_sym)
end
end
def Nitro.inject( services )
ObjectSpace.each_object(Class) do |k|
if k.needs?(:server)
k.class_eval do
define_method{:server){ services[:server] }
end
end
end
end
my_server = Nitro::Server.new
Nitro.inject( :server => my_server )
class Nitro::Element
needs :server
end
T.
More information about the Nitro-general
mailing list