• 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 »

  • My native language

    February 16th, 2009

    Severed head I’m currently reading Nudge, by Richard H. Thaler and Cass R. Sunstein. It says many psychologists and neuroscientists agree that we humans have two general types of thinking, intuitive and rational. Also known as automatic and reflective.  When dodging a ball thrown at you, getting nervous when your aeroplane hits turbulence or smiling when you see a cute cat the automatic system is working.  When doing some mathematics, or writing a blog post, you (mostly) use reflective.  Speaking native, or “first” languages uses the automatic.  Speaking a second language usually uses reflective.

    I realised that having tinkered with computers heavily almost my entire life, a lot of my “computer skills” have shifted into the intuitive, automatic systems.  I obviously (hopefully) use the rational systems a great deal, but underlying it is definitly intuition – the gut feeling of where to go next to solve the problem.  I regularly come up seemingly random avenues of investigation that lead to gold and I couldn’t say with any certainty why I thought of it.  I’m assuming this is the same for most computer geeks (and chess geeks, cooking geeks, music geeks etc. :).  It’s become a native language for us.

    I don’t think the average rational system can easily deal with very complex problems.  It’s great for some more-linear concentrated work or planning, but for big stuff with lots of parts – hard work.  I think I usually research and “pre-process” a bunch of material around a problem using my rational system, then my automatic system gets to work mulling over the bigger picture.  Then when I’m making rational decisions about it, I’m heavily informed by the intuition. Or sometimes just when I’m showering.

    Anyway, not sure where I was going with this other than a “aren’t I great” blog post. The summary would be, don’t rely on your rational systems so much. Give the intuitive some good mulling time. And shower regularly.

    Tags: brains, concious, geek, intuition, neuroscience, programming, psychology, subconcious., thinking

    Posted in Personal, Tech | No 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 »

  • John Leach

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

    • John Open Rights Group demo against "Digital Economy Bill" on 24th March in London: http://www.openrightsgroup.org/campaigns/disconnection 5 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