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


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

Re: [PhillyOnRails] Need help redefining a method


or better yet, send them a patch ;-)

On 6/29/06, Obie Fernandez <obiefernandez@gmail.com> wrote:
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.

Cheers,
Obie

On 6/29/06, Mike Zornek <mikezornek@mikezornek.com> wrote:
> I'm using this Money class in a Rails app of mine:
>
> http://dist.leetsoft.com/api/money/
>
> And in it there is a handy format method
>
> http://dist.leetsoft.com/api/money/classes/Money.html#M000010
>
> 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,
> @currency="USD">
>
> 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?
>
> Thanks
>
> CODE...
>
> require 'Money'
>
> # Reopen Money class to redo the format method to return $0.00 instead of
> 'free'
>
> class Money
>
> alias orig_format format
>
> def format(*rules)
> result = self.orig_format(rules)
> if result == 'free'
> return '$0.00'
> end
> return result
> end
>
> end
>
> ~ Mike
> --
> Work: http://ClickableBliss.com
> Play: http://MikeZornek.com
>
>
> _______________________________________________
> talk mailing list
> talk@phillyonrails.org
> http://lists.phillyonrails.org/mailman/listinfo/talk
>

_______________________________________________
talk mailing list
talk@phillyonrails.org
http://lists.phillyonrails.org/mailman/listinfo/talk