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:

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