watch this  

the official mrchucho blog

Unit Testing Ruby Singletons

Posted 2006 Oct 31

I found an interesting post via reddit about how the Singleton pattern is incompatible with Unit Testing. I’ve certainly encountered difficulties unit testing a Singleton that maintains any sort of state. I posted the following as a comment, but my code didn’t format properly, so here it is:

I’ve encountered this problem recently using Ruby. Thankfully, with Ruby I can create a singleton of my Singleton class for use in my unit tests. In this test-specific singleton I can add “reset” or “clear” method to reset the state. Assuming I have a singleton called “OnlyOne”:
def test_singleton
  class << OnlyOne.instance
    def reset
      # reset state

comments (0)

Clever Ruby Idiom

Posted 2006 Sep 23
Whilst whipping-up another Rbot plugin yesterday, I wanted to concisely say “sometimes do something”. I found this at Ruby Garden
def sometimes
    yield if rand > 0.5
Now I can do this:
sometimes do

I love that!

comments (0)


Posted 2006 Jun 27

<!-contact form->

comments (0)

Encouraging Signs from Yahoo! Dev Network

Posted 2006 Jun 22

Looks like Jeremy Zawodny is back at the Yahoo! Developer Network. I posted my request regarding adding support for Yahoo! Shortcuts. Hopefully we’ll see some action!

comments (0)

Forecast Plugin for Rbot

Posted 2006 Feb 16

Another day, another weather/Ruby/IRC plugin :)

This time it’s an rbot IRC plugin for weather forecasts. It also uses the Yahoo Maps API, so any free-form location works, e.g.

rbot forecast Tulsa, OK


rbot forecast 74104

Download it here: [forecast.rb]

comments (0)

When did Yahoo get so cool?

Posted 2006 Feb 15

I have to say: I’m really impressed with Yahoo! lately. I have used a personalized My Yahoo! for the longest time, but have never really thought of Yahoo as “cool”. First, my encounter with the Yahoo Maps API, then their new ajaxalicious UI library and now a tweaked-out My Yahoo!

The new My Yahoo! has site-specific mini-icons in each of the content bars—which I great because I collate feeds from Reuters, AP,, and others. Besides being drag-and-drop capable, the context boxes also show a mini preview in a tooltip.

I also want to thank Yahoo for adding “Submits over SSL” to the mail login… That saves me like 10,000 clicks over the course of a year ;)

My Yahoo! is the “dashboard” that Dashboard can only hope to be: it’s open, powerful, portable and - now - sexy!

comments (0)


Posted 2006 Feb 08

I was writing another rbot plugin - this time to get forecast data from the NOAA like my Quicksilver plugin [1] - and I needed a good way to get latitude and longitude. A quick search revealed that the Yahoo Maps API provides just such a thing!

Yahoo’s API is REST based, whereas the NOAA uses SOAP. The differences in complexity are significant. Using REST, I simply create a URL. No special software, no WSDL, no libraries. Not even any particularly deep understanding of the underlying technology is required.
    def get_lat_long(loc)
        loc = ERB::Util.u(loc)
That’s it! Now I get back an XML document that I can easily parse with REXML. To do the same thing with SOAP requires a little bit more effort and, to me, doesn’t feel as natural.
class Forecast
    def initialize(lat,long)
    def forecast
        forecast = @forecaster.NDFDgenByDay(
            @lat,@long,"%Y-%m-%d"),2,"24 hourly")
        xml = ("forecast.xml",'w') do |file|
            file < < xml
But, most importantly, you have to use a SOAP client to interact with this service… In the case of Yahoo’s API, I can just type a URL into my browser and get results. This is minor, but can be important when first getting started or when debugging.

1 I’ll post later about the differences in writing this software in Ruby versus Cocoa/Objective-C…

comments (0)

Warcraft Realm Status rbot Plugin

Posted 2006 Jan 30

To pass the time last Friday afternoon, I wrote a plugin for the Ruby IRC bot, rbot, to query the status of World of Warcraft realms.

With a single piece of code, I satisfied both my Ruby and WOW needs…

Thanks to Blizzard for providing Realm Status in an easy-to-use XML format. Thanks to rbot for bringing Ruby to IRC.

Download: realm.rb

comments (0)

Happy New Year!

Posted 2006 Jan 01

Wishing everyone who visits a Happy New Year!

comments (1)

This Window Updated

Posted 2005 Nov 28

I updated my This Window Firefox extension to be compatible with older (1.07) versions of Firefox. I also added it my update.rdf.

comments (0)
atom rss