Permalink
Browse files

Add setter.

Fixes #1.
  • Loading branch information...
1 parent 455cb8e commit 9c46d9f9e082f9b0b07a3b0747eec741d3abdd51 @jnunemaker jnunemaker committed Apr 9, 2012
Showing with 10 additions and 1 deletion.
  1. +4 −0 lib/morphine.rb
  2. +6 −1 spec/morphine_spec.rb
View
@@ -14,6 +14,10 @@ def register(name, &block)
define_method name do
dependencies[name] ||= instance_eval(&block)
end
+
+ define_method "#{name}=" do |service|
+ dependencies[name] = service
+ end
end
end
end
@@ -26,5 +26,10 @@
Container().register(:service) { Struct.new(:client).new(client) }
container.service.client.should == container.client
end
+
+ it 'defines writer method to change service' do
+ container.client = 'new client'
+ container.client.should eq('new client')
+ end
end
-end
+end

0 comments on commit 9c46d9f

Please sign in to comment.