All:
This is probably going to seem a bit silly, however I will ask
anyway.
Is there a way to override the to_s method such that it takes a
parameter? For example, if I wanted to provide a format specifier
for a number:
class Numeric
def to_s(optFormat)
if !optFormat.nil?
# format a string based on the optFormat format
# specifier.
retVal = format_number(self,optFormat)
else
retVal = self.to_s
end
retVal
end
end
payment=600 # $6.00
puts(payment.to_s('$#.##'))
(* not a perfect specimen of a ruby script, but it gets the
idea across *)
Any help with this matter, is greatly appreciated.
Regards,
Brad