 # @signatures is just an array, not a hash.  It will not grow very large
 # so a linear search for a particular signature is fine.
 #
+# @signatures and @state are added to the mock object by the various mock 
+# methods when needed (i.e. lazily); if we mock an existing class then we
+# only need to worry about adding the mock methods to that class, not 
+# monkeying with its contructor to also add @signatures and @state.
+#
 class Mock
-
-  constructor: ->
-    @signatures = []
-    @state = undefined
 
   #
   # my_mock = (new Mock).expects("my_method")

# Private Mock 'methods'; making them functions keeps the Mock object uncluttered.
#

_set_state = (mock, state) ->
  mock.state = state



_check_for_duplicate_signatures = (mock) ->
  # TODO: use each with index and slice to avoid last element
  signatures = _signatures(mock)
  return if signatures.length < 2
  for outer in [0..signatures.length-2]
    for inner in [outer+1..signatures.length-1]
      _throw_duplicate_expectation("#{signatures[outer].method_name}(#{signatures[outer].args})") if signatures[outer].equals( signatures[inner] )

_current_signature = (mock) ->
  _signatures(mock)[0]

_current_method_name = (mock) ->
  _current_signature(mock)?.method_name

_find_signature = (mock, method_name, args...) ->
  for signature in _signatures(mock) when signature.matches(method_name, args...)
    return signature
  undefined

