Skip to content

Instantly share code, notes, and snippets.

@avit
Created July 24, 2012 21:37
Show Gist options
  • Save avit/3172840 to your computer and use it in GitHub Desktop.
Save avit/3172840 to your computer and use it in GitHub Desktop.
model arithmetic
describe Rate do
it "can do arithmetic" do
total = Rate.new(amount: 100.00) + Rate.new(amount: 200.00)
total.should == 300.00
end
end
class Rate < ActiveRecord::Base
attr_accessible :amount
delegate :+, :-, :/, :*, :to_d, :to_f, :to_i, :to => :amount
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment