Commits

Kaspar Schiess  committed 056b544

Allows as in block form for transformation

  • Participants
  • Parent commits e680161

Comments (0)

Files changed (2)

File lib/par/result.rb

     def maybe
       self
     end
-    def as obj
-      Result.new(obj)
+    def as replacement=nil, &block
+      unless block_given?
+        return Result.new(replacement)
+      end
+
+      return Result.new(block.call(@obj))
     end
 
     def new obj

File spec/lib/par/result_spec.rb

     end
     it "allows replacing contents using .as(obj)" do
       r.as(nil).should == nil
-    end 
+    end
+    it 'allows transforming object contents' do
+      r.as { |o| o + 's' }.should == 'rs'
+    end
   end
   context 'given 2 results' do
     let(:a) { result 'foo' }