Phillip Gawlowski wrote:
So, let's do a Classic version (pardon the pun):
~ attr_reader :friend, :vet, :super_vet
~ def initialize
~ @friend, @vet, @super_vet = 40, 100, 160
~ def method_missing
~ 0 # The default 'discount'
discount_for = Discounts.new
Beware of bugs; I've only proved the code correct, not tested it.
Well, not even that bit of due diligence. *sighs*
Obviously, that doesn't work.
discount_for.vet # that does work with the above code.
However, defining a singleton method would provide what I like to see.
def discounts_for buyer
~ case buyer
~ when friend : 40
~ else 0
Or define it as a class method:
~ # Handling of variables left out as exercise for the reader
~ def self.for
That way you could call, for example:
~ - You know you've been hacking too long when...
...you send E-mail and end each line with \n.