Created
March 7, 2015 17:22
Revisions
-
johnkpaul created this gist
Mar 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ class SumOfFactors def initialize(until_num, *divisible_by) @until_num = until_num @divisible_by = divisible_by end def get_sum get_range.select(&self.method(:is_disivible_by)) .inject(&self.method(:sum_arr)) end private def sum_arr(sum, num) sum + num end def is_disivible_by num @divisible_by.any? {|divisible_by| num % divisible_by == 0 } end def get_range (1..@until_num) end end sum = SumOfFactors.new(100, 3, 5).get_sum puts sum