Ruby's awesomely dangerous awesomeness
October 31, 2008 📬 Get My Weekly Newsletter ☞
While packaging my resume creator/formatter as a Ruby Gem, I noticed my command line parser was preventing my code from running. It has this hook that sets up an "auto run" sequence (your code just defines a main method): the problem is that $0 from gem is the /usr/bin location and @@appname is the actual location in the Gem repository. Not sure why this check was there, but I had a problem.
Not feeling like overhauling the command line interface code and not being able to patch OptionParser, I opted instead to use the dangerous-sounding ruby feature of replacing the method with my own implementation: Now that's pretty cool. My code just dynamically patches the broken Gem! The power of open source and dynamic languages. Of course, this feature allows so much awful code to be written....