Avoid calling nested method two times For a given file name path, I need to get the folder one level before it. This can be accomplished in ruby with the following code:

File.dirname(File.dirname("/a/b/c.txt"))
 =&gt; "/a" 


Independently from this exact case, how can I DRY two method calls in sequence?
You should consider any DRYing efforts in terms of its effects on code clarity. I don't think that trying to reduce foo(foo(bar)) is worth the reduced clarity. Now, if we're trying to reduce foo(foo(foo(foo(foo(bar))))), that's something else. One way you can do that is using reduce:

5.times.reduce(1 &lt;&lt; 64) { |x,| Math.sqrt(x) }
=&gt; 4.0

5.times.reduce('/a/b/c/d/e/f.txt') { |x,| File.dirname(x) }
=&gt; "/a"