The GP2D02 is a neat digital distance sensor made by Sharp which uses reflected IR light to measure distances from about 3" to 3' (I think it's been discontinued now though). The fact that it has a digital output is convenient when using a microcontroller, although since the Arduino has analog inputs you might also consider using the analog variants like the GP2D12 or GP2Y0A02 instead.
To install the libary, you need to download GP2D02.zip and place the GP2D02 directory into the Arduino libraries directory and then restart the Arduino IDE.
Once you've installed the library you can set up a sensor like this:
| GP2D02|---White--->|---|Pin 2 (note the interfacing diode)
|_______|---Yellow ------|Pin 7
const int INPUT_DATA_PIN = 7;
const int OUTPUT_CLOCK_PIN = 2;
Then you can get the distance from it like this:
byte distance = distanceSensor.read();
And that's it!
(Note that the shift-in function in the library was adopted from http://www.arduino.cc/en/Tutorial/ShftIn22 and modified in order to account for the timing requirements of the GP2D02 sensor)