From 28f4bf1cd1acb0e1c323ffafb88bd7b74c768157 Mon Sep 17 00:00:00 2001 From: Inuka Wijerathna Date: Fri, 5 Jun 2026 10:44:03 +0530 Subject: [PATCH] Add ReturnOnInvestment to maths --- maths/return_on_investment.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 maths/return_on_investment.rb diff --git a/maths/return_on_investment.rb b/maths/return_on_investment.rb new file mode 100644 index 0000000..aca9cc1 --- /dev/null +++ b/maths/return_on_investment.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Calculates Return on Investment (ROI) as a percentage. +# ROI measures the profitability of an investment relative to its cost. +# +# Formula: ROI = (Gain - Cost) / Cost * 100 +# Reference: https://www.investopedia.com/terms/r/returnoninvestment.asp +class ReturnOnInvestment + def self.call(gain_from_investment, cost_of_investment) + raise ArgumentError, 'cost_of_investment must be greater than 0' if cost_of_investment <= 0 + + (gain_from_investment - cost_of_investment).to_f / cost_of_investment * 100 + end +end