Skip to content

Instantly share code, notes, and snippets.

@arches
Created December 19, 2012 20:28
Show Gist options
  • Select an option

  • Save arches/4340174 to your computer and use it in GitHub Desktop.

Select an option

Save arches/4340174 to your computer and use it in GitHub Desktop.
module Discountable
def to_discount_code
DiscountCode.find_by_code(self)
end
end
class DiscountCode < ActiveRecord::Base
def to_discount_code
self
end
def to_s
code_string
end
end
my_code = "s8ej1k"
my_code.extend(Discountable)
my_code.to_discount_code # DiscountCode
my_code.to_discount_code # DiscountCode
my_code.to_s # "s8ej1k"
@arches
Copy link
Author

arches commented Dec 19, 2012

it's like a cup-and-ball game. Watch very carefully... my_code.to_discount_code.to_discount_code.to_s.to_discount_code.to_s.to_s.to_discount_code Ok now, which object has the database ID? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment