Guy's Hook Patch for Ruby 1.8
He said it was a toy, so I figured I would play with it. This patch provides a single colon of syntactic sugar for hooking a method. The hook is called before the method call.
class Array
def shift:hook()
p "Removing #{self.first}"
end
end
arr = [1, 2, 3]
arr.shift
The above prints Removing 1. You can run the original method with super.
Kinda interesting. It kind of sparks the mind to think what could be done if we were allowed to add code to blocks. In the case of a hook, we’re merely adding code to the beginning of a method. Hmm. I dunno.
Incident No. 16: The Skier
One man had become such an impulsive skier that he started skiing down dirt roads in the summer. It actually wasn’t such a bad sport and the guy won a silver medal when Dust Country Skiing went national.
The fashion these people wore was atrocious, though. It was common to see ski poles with leather tassles on the handles and such nonsense.
Incident No. 15: The Man Who Happened to Have Legs
One of the first strange things to ever happen was when a man was born and turned out to be nothing more than twelve legs coming from a cloud. When people saw him, they usually ended up thinking that he was David Blaine or some other magician pulling a stunt.
So David Blaine got a really bad rap about it and people started putting a lot of pressure on him to do regular card tricks that just told a story or something.
Incident No. 14: The Man Who Happened to Reach Up
There was a man who happened to reach up higher than anyone ever had before, so his hand got stuck in a cloud. And he got dragged all over the sky.
A lot of his old buddies really got a kick out of seeing him fly by whenever they showed weather maps on the news.