<p>Scenario: I have a function that I need to tweak in some way (example; make it work slightly different in different places). For some reason I end up having to add something ugly to the code, either in the function or at existing call sites. Assume that the sum total "ugly" is the same in both cases.</p>

<p>The question is which choice should I pick and why? </p>

<p>Should I encapsulate it so I don't need to look at it or should I extract it so that it doesn't add semantic trash to the function?</p>

<p>What would effect your choice? What about if:</p>

<ul>
<li>The function will "never" be called except from the current locations.</li>
<li>New calls to the function won't need the "ugliness".</li>
<li>The function is really clean and generic right now</li>
<li>The function is already a hack job.</li>
<li>you wrote the function</li>
<li>you didn't wright the function</li>
<li>etc.</li>
</ul>

Put the ugly in the function, hands down. If this is in C++ be sure to have the implementation in the .cpp file. Perhaps you may consider writing two functions to abstract the ugly from the main function body.
Procedural/OOP programming exists to take the "ugly" out of the interface (among other things). It is important to realize that the more code that is required to call the function the less useful it becomes. Also remember to document the code clearly and note that there is ugly code in there and why.
Also, if this function is big enough you may consider putting it in its own .cs file, or .cpp/.h pair (depending on which language you are using).