DRY a large chunk of common code with two vastly different uses <p>I have a 'widget' that comprises an html/css block of code. It is a type of data layout, which I call the <b>'stack'</b>.</p> <p>The stack has bits of <code>.erb</code> (Ruby on Rails) embedded in it, which enters the data for each user.</p> <p>I need to include this stack in multiple places, where it needs to represent <b>different data from different models</b>.</p> <p>So, one stack might contain a field called <code>@company.name</code> and the other stack might contain <code>@project.name || "Unidentified Project"</code>.</p> <p>How does one refactor / organize this situation? Options that I can see:</p> <ol> <li>Have two separate <code>stacks</code>, which would introduce redundancy and inconsistency, but would be an obvious answer to the problem without limit to scenario-specific customization.</li> <li>Include <code>if</code> statements for every data point to test which circumstance the stack is being used for, but this is very code-ugly and unsustainably complicated for more than 2 stacks.</li> <li>Some unknown unknown.</li> </ol> <p>How would you tackle this?</p>