• Home
  • Personal
  • Tech
  • Politics
  • Photography
  • Ruby’s case statement uses ===

    August 30th, 2009

    I’ve not found this stated clearly enough elsewhere so I’m doing so myself.

    Ruby’s case statement calls the === method on the argument to each of the when statements

    So, this example:

    case my_number
      when 6883
        :prime
    end
    

    Will execute 6883 === my_number

    This is all fine and dandy, because the === method on a Fixnum instance does what you’d expect in this scenario.

    However, the === method on the Fixnum class does something different. It’s an alias of is_a?

    That is cute, because it allows you to do this:

    case my_number
      when Fixnum
        "Easy to memorize"
      when Bignum
        "Hard to memorize"
      end
    

    But it won’t work as you might expect in this scenario:

    my_type = Fixnum
    case my_type
      when Fixnum
        "Fixed number"
    end
    

    This won’t work because Fixnum === Fixnum returns false because the Fixnum class is not an instance of Fixnum.

    My workaround for this is to convert it to a string first. Not sure if that’s the best solution, but it works for me(tm).

    my_type = Fixnum
    case my_type.to_s
      when "Fixnum"
        "Fixed number"
    end
    
    Tags: case, coding, condiitonal, programming, ruby, switch, when

    Posted in Ruby, Tech | 5 Comments »

  • Leeds Ruby Thing #2, Thursday 6th March

    March 4th, 2008

    The Leeds offshoot of the North West Ruby User Group is meeting again this Thursday, 6th March, 7:00 PM – 11:00 PM.  This time at Mr. Foley’s
    Cask Ale House
    , on The Headrow (formerly Dr. Okells).

    Expect unstructured discussion of Ruby, Ruby on Rails and other random stuff plus nice people, great beer and coffee and geeky tshirts.

    The balcony back room of Mr Foley’s has been booked.  Announce that you’re coming on the upcoming page.

    Oh, and we now have a website: http://leedsrubything.org/

    Tags: beer, coding, geek, leeds, nwrug, programming, rails, ruby, social

    Posted in Ruby on Rails, Tech | No Comments »

  • Leeds Ruby Thing, Victoria Hotel 7th Feb 2008.

    February 3rd, 2008

    Some of the people of the North West Ruby User Group (who usually meet in Manchester) have organised the first little Leeds get together.  No real name yet, so it’s the Leeds Ruby Thing for now.

    No clear plan yet either, but expect unstructured discussion of Ruby and Ruby on Rails at least.

    Thursday 7th February 2008 at 7pm in the Victoria Hotel pub. All welcome!

    More details here: http://upcoming.yahoo.com/event/423116

    Tags: beer, coding, leeds, meetup, nwrug, programming, pub, rails, ruby, social

    Posted in Ruby on Rails | 1 Comment »

  • Cute Little Image Gallery Script (CLIGS)

    March 20th, 2005

    The Cute Little Image Gallery Script (CLIGS) is a PHP script that autogenerates a nice html index for a directory full of jpeg images. I wrote it to run my photography galleries and have released it to the world under the Gnu Public License (GPL). Download it and give it a bash (needs some setup and Apache trickery to get going).

    Tags: coding, gallery

    Posted in Photography, Tech | No Comments »

  • Qmail, RedHat and Firestorm

    December 11th, 2003

    I’ve built some packages of djbs software (qmail, daemontools, djbdns…) for RedHat ES.

    I’ve also been working on Firestorm again, primarily on my mac/arp watcher preprocessor. It now saves state between restarts, and reports on more nefarious ethernet/arp. It’ll be included in the next release of Firestorm.

    Tags: coding, firestormnids, nids, qmail, redhat, rhes

    Posted in Networks and Firewalls, Tech | No Comments »

  • Subversion

    November 9th, 2003

    I’ve upgraded to subversion for version tracking of source code instead of moudly old cvs. I had a little trouble keeping my old modification history but don’t really care. The only feature I’m missing is the Log keyword that I used to add to the bottom of my html pages as a comment. Otherwise I’ve been very impressed. I’m working on getting a viewcvs interface up for a remote copy of my repository soon.

    Tags: coding, cvs, subversion

    Posted in Tech | No Comments »

  • gthumb diff and website changes

    July 15th, 2003

    I’m back from my holiday in the Czech Republic.

    I’ve rejigged my website a little to make it easier to see where things are on the front page.

    I produced the web albums using Gthumb by Paolo Bacchilega. I need a little feature it seemed to lack (or a bug prevented it) so I wrote a patch to add it. This patch changed the behaviour of the Tools->Change Date tool. For each file that it changes the last modified date, it now also sets the comment date. You should be able to do this in Properties but a bug causes all images to be set with the first image’s date. I couldn’t see how to add this functionality there anyway. According to Paolo, this is now fixed in ver 2.1.3 so this patch is redundant.

    Tags: coding, gthumb, photos, prague

    Posted in Tech | No Comments »

  • horribly ported

    April 26th, 2003

    My port of that pptpd exploit to Linux was apparently so horrendous that it prompted ‘r4nc0rwh0r3′ of ‘blightninjas’ to take the time to do it properly. In my defence, the original code really sucked, and I myself only needed the testing part to work (which seemed to work for me). It also compiled fine for me with gcc 3.2.3 (worksforme(tm)). And I in no way proclaim myself to be a good C programmer! Anyway, my laziness and lameness was thoroughly ridiculed by them here. Find their own fixed version here. At least I got my name on Bugtraq. Roll on fame and the big dollar.

    Tags: bugtraq, coding, linux, Security, sploit

    Posted in Security, Tech | No Comments »

  • John Leach

    • John Leach is a human being living in Leeds, UK.
  • Twitter

    • John ooh, I bug I reported in libvirt in Ubuntu Hardy in May 2008 just got into hardy-proposed! The system works! http://is.gd/aJzU7 8 hrs ago
    • More twitter updates →
  • Author Stuff

    • Brightbox Rails Hosting
    • Compost This
    • ELER Web Comic
    • New World Odour
    • News Sniffer
    • Photography
    • Profile and History
    • Recycle This
    • The Gillroyd Parade
    • Things to do today
    • Website
  • Friends

    • Caius Durling
    • Deb Bassett
    • Gianni Tedesco
    • Ian Higgins
    • Louisa Parry
    • Rahoul Baruah
    • Sleepy Kev
    • Tim Waters
    • Tom Hall
  • Stuff

    • ifup
    • Media Lens
    • Mia Bambina
    • News from nowhere
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
  • Search

Creative Commons License The text of this blog is licensed under the Creative Commons BY-ND license