The calendar is gone.
Click here to view posts


Ruby underscore
Looking in to patching Hpricot for work and I found this bit of code

tagname, _, attrs, sraw, _, _, _, eraw = structure[1]

I first thought 'What is structure returning' but I was drawn to the _ (underscore) . I first thought that it was a pre-defined variables but I could not find it listed. So I fired up irb.
x,_,y = *[1,2,3] # >] [1, 2, 3] [<

_ # >] [1, 2, 3] [<

x # >] 1 [<

_ # >] 1 [<

The * in front of array just takes the contents of the array allow me to do multiple assignment. I would expect x to be 1, _ (underscore) would be 2, and y would be 3. When I display _ (underscore) it shows the the original array again. Then I print x which is 1 and then I print _ (underscore) again and it is now 1.
The example above is not good. It almost looks like the underscore is returning the right side of the assignment.
 
"asdf".sub("a","t") # "tsdf"

_ # "tsdf"

Fun