Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add setter #2

Merged
merged 1 commit into from about 2 years ago

1 participant

John Nunemaker
John Nunemaker

Added setter method for each registered service.

John Nunemaker jnunemaker merged commit 9c46d9f into from April 09, 2012
John Nunemaker jnunemaker closed this April 09, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 09, 2012
John Nunemaker Add setter.
Fixes #1.
9c46d9f
This page is out of date. Refresh to see the latest.
4  lib/morphine.rb
@@ -14,6 +14,10 @@ def register(name, &block)
14 14
       define_method name do
15 15
         dependencies[name] ||= instance_eval(&block)
16 16
       end
  17
+
  18
+      define_method "#{name}=" do |service|
  19
+        dependencies[name] = service
  20
+      end
17 21
     end
18 22
   end
19 23
 end
7  spec/morphine_spec.rb
@@ -26,5 +26,10 @@
26 26
       Container().register(:service) { Struct.new(:client).new(client) }
27 27
       container.service.client.should == container.client
28 28
     end
  29
+
  30
+    it 'defines writer method to change service' do
  31
+      container.client = 'new client'
  32
+      container.client.should eq('new client')
  33
+    end
29 34
   end
30  
-end
  35
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.