Obie Fernandez on 29 Jun 2006 14:09:15 -0000

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PhillyOnRails] Need help redefining a method

result = self.orig_format(*rules) # keep the args splatted

However, if I were you I would send a request to the maintainer of the
library for a new :spell_out_free rule. It was silly of them not to do
that to begin with.


On 6/29/06, Mike Zornek <> wrote:
I'm using this Money class in a Rails app of mine:

And in it there is a handy format method

I have an issue with it spitting out 'free' (when the cents value is zero)
though so I want to override the class to return '$0.00' where it would have
returned 'free'. My code is below but it's not working. I get an error like:

private method `orig_format' called for #<Money:0x2507104 @cents=995,

I've tried other incatations and have gotten an error like:

can't convert Array into String

This happened on the line containing `self.orig_format(rules)`

Any ideas on how I should be doing this?



require 'Money'

# Reopen Money class to redo the format method to return $0.00 instead of

class Money

alias orig_format format

def format(*rules)
result = self.orig_format(rules)
if result == 'free'
return '$0.00'
return result


~ Mike

_______________________________________________ talk mailing list

talk mailing list