Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 03/04/2009

Joseph Palermo
Wednesday, March 4, 2009

Interesting Things

Integer("008") != "008".to_i
  • The to_i method is what you want, unless you want exceptions or octal numbers.

  • Somebody needed help constructing a named_scope where they could reference the count of an associated has_many association. There was some grumbling about using :joins and :group (and if you do this, be sure not to call count on the scope itself without also doing a :select => 'DISTINCT primary_key'). The winning solution was to just put a counter_cache on the association and use the denormalized column instead.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

One comment

  1. Erik Hanson says:

    Javascript’s parseInt() has a similar issue:


    parseInt("8") === 8

    parseInt("08") === 0

    parseInt("010") === 8

    One solution is to include the radix:


    parseInt("08", 10) === 8

    Or use the Number function or constructor:


    Number("08") === 8

    new Number("08") === 8

    Another trick is to convert the string using the + operator:


    +"08" === 8

    March 7, 2009 at 4:45 pm

Add New Comment Cancel reply

Your email address will not be published.

Joseph Palermo

Joseph Palermo
San Francisco

Recent Posts

  • Why Pivots don’t do their best work at night
  • [Standup][SF] 08/28/12: They at least strongly dislike each other
  • 06/26/12: Headless is fine, double headless is trouble
Subscribe to Joseph's Feed

Author Topics

agile (18)
named_scope (1)
ruby on rails (2)
bug (1)
performance (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >