Mike Zornek on 29 Jun 2006 05:29:36 -0000

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

[PhillyOnRails] Need help redefining a method

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
Work: http://ClickableBliss.com
Play: http://MikeZornek.com

talk mailing list