[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Mutually-Recursive Functions

Gavin Kistner

6/7/2007 6:37:00 PM

From: bbiker [mailto:renard@nc.rr.com]
Sent: Thursday, June 07, 2007 12:00 PM

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

I thought I'd point out that
'A'[0]
is equivalent to
?A
...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 = Hash.new{ |h,alpha|
offset = ?A - 1
alpha.upcase!
case alpha.size
when 1
h[alpha] = alpha[0] - offset
when 2
h[alpha] = ( alpha[0] - offset ) * 26 +
( alpha[1] - offset )
end
}