Sure. Just cast on the correct number of stitches for the pattern (42) and knit however many rows of 1,1 or 2,2 or whatever ribbing pattern you'd like (1,1 is K1, P1; 2,2 is K2, P2), as long as it's an even number.
Write down the number of rows, or the number of inches/cm, the ribbing takes up (probably on the pattern?) and, when the scarf is as long as you'd like it to be, knit the same amount of ribbing again.
Voilá! a scarf!