I looked at the Quiz resume in Solitaire Cipher when I came across this block of code:
def triple_cut
a = @deck.index( 'A' )
b = @deck.index( 'B' )
a, b = b, a if a > b
@deck.replace( [ @deck[(b + 1)..-1],
@deck[a..b],
@deck[0...a] ].flatten )
end
I do not understand why there is a separate method for this replace. Why not just do the following?
@deck = @deck[(b + 1)..-1] +
@deck[a..b] +
@deck[0...a]
Why use two different methods ( replaceand flatten) when you can just add them together? I have not encountered any problems.
source
share