<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,35 +37,45 @@ module Clipper
       end
 
       def typecast_left(*args)
-        matching_types = true
-        @repository_types.each_with_index do |type, i|
-          unless args[i] == nil || args[i].is_a?(type)
-            matching_types = false
-            break
-          end
-        end
-
-        unless matching_types
-          raise ArgumentError.new(&quot;Expected args to be instances of #{@repository_types.inspect} but was #{args.inspect}.&quot;)
-        end
-
-        @typecast_left_procedure.call(*args)
+        convert(@repository_types, @attribute_types, @typecast_left_procedure, args)
       end
 
       def typecast_right(*args)
-        matching_types = true
-        @attribute_types.each_with_index do |type, i|
-          unless args[i] == nil || args[i].is_a?(type)
-            matching_types = false
-            break
+        convert(@attribute_types, @repository_types, @typecast_right_procedure, args)
+      end
+
+      private
+        def convert(source_types, target_types, typecast_procedure, args)
+          matching_types = true
+          source_types.each_with_index do |type, i|
+            unless args[i] == nil || args[i].is_a?(type)
+              matching_types = false
+              break
+            end
+          end
+
+          unless matching_types
+            raise ArgumentError.new(&quot;Expected args to be instances of #{source_types.inspect} but was #{args.inspect}.&quot;)
           end
-        end
 
-        unless matching_types
-          raise ArgumentError.new(&quot;Expected args to be instances of #{@attribute_types.inspect} but was #{args.inspect}.&quot;)
+          value = typecast_procedure.call(*args)
+
+          case value
+          when nil then nil
+          when Array then
+            target_types.each_with_index do |type, i|
+              unless value[i] == nil || value[i].is_a?(type)
+                raise ArgumentError.new(&quot;Expected value to be an instance of #{type} but was #{value[i].inspect}&quot;)
+              end
+            end
+          else
+            if target_types.size == 1 &amp;&amp; value.is_a?(target_types.first)
+              value
+            else
+              raise ArgumentError.new(&quot;Expected value to be an instance of #{target_types.first} but was #{value.inspect}&quot;)
+            end
+          end
         end
-        @typecast_right_procedure.call(*args)
-      end
     end # class Signature
   end # class TypeMap
 end # module Clipper
\ No newline at end of file</diff>
      <filename>lib/clipper/type_map/signature.rb</filename>
    </modified>
    <modified>
      <diff>@@ -93,9 +93,58 @@ class SignatureTest &lt; Test::Unit::TestCase
       signature.typecast_left(nil)
     end
 
+    assert_nothing_raised do
+      signature.typecast_right(&quot;1&quot;)
+    end
+  end
+
+  def test_type_casting_verifies_value_type
+    typecast_left_procedure = lambda { |age| age.to_s }
+    typecast_right_procedure = lambda { |age| age.to_i }
+
+    signature = Clipper::TypeMap::Signature.new(
+      [String],
+      [Integer],
+      typecast_left_procedure,
+      typecast_right_procedure
+    )
+
     assert_raises(ArgumentError) do
       signature.typecast_left(&quot;one&quot;)
     end
   end
 
+  def test_type_casting_verifies_return_type
+    typecast_left_procedure = lambda { |age| age.to_s }
+    typecast_right_procedure = lambda { |age| age.to_i }
+
+    signature = Clipper::TypeMap::Signature.new(
+      [String],
+      [Integer],
+      typecast_left_procedure,
+      typecast_right_procedure
+    )
+
+    assert_nothing_raised do
+      signature.typecast_right(&quot;one&quot;)
+    end
+
+    typecast_right_procedure = lambda { |age| Integer(age) rescue age }
+
+    assert_nothing_raised do
+      assert_equal(&quot;one&quot;, typecast_right_procedure.call(&quot;one&quot;))
+    end
+
+    signature = Clipper::TypeMap::Signature.new(
+      [String],
+      [Integer],
+      typecast_left_procedure,
+      typecast_right_procedure
+    )
+
+    assert_raises(ArgumentError) do
+      signature.typecast_right(&quot;one&quot;)
+    end
+  end
+
 end
\ No newline at end of file</diff>
      <filename>tests/unit/signature_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9c884236f2e974d5d2b592765f6f552f6fe41a5e</id>
    </parent>
  </parents>
  <author>
    <name>Sam Smoot</name>
    <email>ssmoot@gmail.com</email>
  </author>
  <url>http://github.com/wiecklabs/clipper/commit/d918af4ef8d8b219a0082a73abb08e94e0b570fd</url>
  <id>d918af4ef8d8b219a0082a73abb08e94e0b570fd</id>
  <committed-date>2009-06-22T14:42:00-07:00</committed-date>
  <authored-date>2009-06-22T14:42:00-07:00</authored-date>
  <message>I think this should finish off the Signature.</message>
  <tree>1fe32cfb121a67d3f3b1210060960938e1df61c7</tree>
  <committer>
    <name>Sam Smoot</name>
    <email>ssmoot@gmail.com</email>
  </committer>
</commit>
