Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Created May 13, 2013 22:39
Show Gist options
  • Select an option

  • Save gogogarrett/5572114 to your computer and use it in GitHub Desktop.

Select an option

Save gogogarrett/5572114 to your computer and use it in GitHub Desktop.
A very simplistic implementation of a point ledger class that adds and deducts by creating user point transactions.
class PointLedger
attr_reader :student
def initialize(student)
@student = student
end
def add(amount, item)
create_point_transaction(amount, item)
student.points += amount
student
end
def deduct(amount, item)
create_point_transaction(-amount, item)
student.points -= amount
student
end
private
def create_point_transaction(amount, item)
student.point_transactions.build(amount: amount, item_type: item.class.to_s, item_name: item.name)
end
end
class PurchaseCalc
def possible?(points, item_price)
points >= item_price
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment