C
Charles Comstock
Hi,
There have been a few times in which I have wanted to destructively change the
type of a variable, yet as fas I can determine there are only to_i and to_f and
not to_i! or to_f!. It seemed like these would be useful sets of methods to
have in addition to the existing to_i, to_f methods. In particular this would
be nice for situations like:
ARGV[0].to_i!
if(ARGV[0] > 5) {...}
or if you had read in a config file into keyname/value string pairs in a hash
I commonly find myself using something like:
config['accuracy'] = config['accuracy'].to_i
this would be much simpler if it was simply
config['radix'].to_i!
While not as useful in expression statements these would be nice and analogous
to the +=, -= operators that automatically get defined based on definition of
the matching operator. It would be nice if the type conversion methods had
something that was similar to that.
Anyway, seemed useful to me, wondered what everyone else thought,
Charles Comstock
There have been a few times in which I have wanted to destructively change the
type of a variable, yet as fas I can determine there are only to_i and to_f and
not to_i! or to_f!. It seemed like these would be useful sets of methods to
have in addition to the existing to_i, to_f methods. In particular this would
be nice for situations like:
ARGV[0].to_i!
if(ARGV[0] > 5) {...}
or if you had read in a config file into keyname/value string pairs in a hash
I commonly find myself using something like:
config['accuracy'] = config['accuracy'].to_i
this would be much simpler if it was simply
config['radix'].to_i!
While not as useful in expression statements these would be nice and analogous
to the +=, -= operators that automatically get defined based on definition of
the matching operator. It would be nice if the type conversion methods had
something that was similar to that.
Anyway, seemed useful to me, wondered what everyone else thought,
Charles Comstock