From: John Joyce Date: 2007-05-12T18:55:00+09:00 Subject: Re: Shift Operators - I don't get it? What's the application?!? It's not what you think. Not always. It's not a bit shift operator all the time. << is a bit different in different contexts in Ruby. You can look it up with the tool ri ri '<<' That will give you a list of different classes that use << In the Array class for example, << pushes an object on the right side onto the end of the array on the left side. an_array << object_to_push_onto_end In the class BigNum and the class FixNum, << is a left shift bit shift operator. Bit shifting isn't often done in Ruby, but certainly possible. It has various uses and is often used for speed tricks in C, because bit shifting is some times faster than some math operations. It litterally takes a binary number and moves all the 1's and zeros to the left. (to the right with >>) With class IO (and its subclasses, such as File) << writes the object on the right to the IO object on the left. It also converts the object on the right to a string first. Class String uses << to append the object on the right to the string object on the left. Conversion to string first will happen. This may actually be a weakness of Ruby, maybe not. (could be a contentious issue) but much like in natural languages, context makes it pretty clear that something different is happening. If you really want a tutorial on how bit-shifting works, there should be a few good ones out there on the web, or maybe somebody else here will do it. I always hated bit-shifting and bit-filters. (Dan Gookin's, C All-in-one Desk Reference for Dummies has a good bitwise operator chapter.)