Forum: Ruby Re: Mutually-Recursive Functions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
825738339f48c5b8b2a72c02caf3d91c?d=identicon&s=25 Gavin Kistner (Guest)
on 2007-06-07 20:38
(Received via mailing list)
From: bbiker []
Sent: Thursday, June 07, 2007 12:00 PM

>     return alpha_col[0] - 'A'[0] + 1

I thought I'd point out that
is equivalent to
...and I personally find the latter to be much more friendly.

For completeness, here's how I'd write the name-to-number conversion as
an auto-caching hash (without the bounds tests):

COL_NUM ={ |h,alpha|
  offset = ?A - 1
  case alpha.size
    when 1
      h[alpha] = alpha[0] - offset
    when 2
      h[alpha] = ( alpha[0] - offset ) * 26 +
                 ( alpha[1] - offset )
This topic is locked and can not be replied to.